Advertisement
viettiennguyen029

Linked objects with animations

Mar 25th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. // Read data of sprites and animations from file.
  2. void LoadSprites(int id, LPCWSTR tex, LPCWSTR sprite_data, LPCWSTR animation_data)
  3. {
  4.     textures->Add(id, tex);
  5.     LPDIRECT3DTEXTURE9 texture = textures->Get(id);
  6.  
  7.     ifstream spriteReader, animationReader;
  8.  
  9.     spriteReader.open(sprite_data);
  10.     animationReader.open(animation_data);
  11.  
  12.     if (spriteReader.fail())
  13.     {
  14.         DebugOut(L"[ERROR] LoadSprites failed!: ID=%d", id);
  15.         spriteReader.close();
  16.         return;
  17.     }
  18.  
  19.     if (animationReader.fail())
  20.     {
  21.         DebugOut(L"[ERROR] LoadAnimation failed!: ID=%d", id);
  22.         animationReader.close();
  23.         return;
  24.     }
  25.  
  26.     // Load sprite data
  27.  
  28.     string spriteid;
  29.     int left, top, right, bottom;
  30.  
  31.     while (spriteReader >> spriteid >> left >> top >> right >> bottom)
  32.         sprites->Add(spriteid, left, top, right, bottom, texture);
  33.  
  34.     spriteReader.close();
  35.  
  36.     // Load animation data
  37.  
  38.     string animationId;
  39.     string line;
  40.     string spriteId;
  41.     int frameTime;
  42.  
  43.     while (getline(animationReader, line))
  44.     {
  45.         LPANIMATION ani = new Animation();
  46.  
  47.         istringstream iss(line, istringstream::in);
  48.         iss >> animationId;
  49.  
  50.         while (iss >> spriteId >> frameTime)
  51.             ani->Add(spriteId, frameTime);
  52.  
  53.         animations->Add(animationId, ani);
  54.     }
  55.  
  56.     animationReader.close();
  57. }
  58.  
  59. LoadSprites(ID_TEX_SIMON, L"Textures\\Simon.png", L"Textures\\Simon_sprites.txt", L"Textures\\Simon_animations.txt");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement