Guest User

Untitled

a guest
Mar 6th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. void Config::configure(AnimationManager *animationManager)
  2. {
  3.     /* Make sure the animations category exists */
  4.     if (root_node["animations"])
  5.     {
  6.         /* Iterate trough each category(each animation) */
  7.         for (YAML::iterator it = root_node["animations"].begin(); it != root_node["animations"].end(); ++it)
  8.         {
  9.             /* Create an animation object */
  10.             Animation* animation = new Animation();
  11.  
  12.             /* Grab the identifier/key which is used to identify this animation */
  13.             animation->identifier = it->first.as<std::string>();
  14.            
  15.             /* Grab the image and load it on the fly as a texture */
  16.             animation->m_texture = SpriteManager::loadImage(it->second["image"].as<std::string>());
  17.  
  18.             /* Fetch the frame_duration */
  19.             animation->frame_duration = it->second["frame_duration"].as<int>();
  20.  
  21.             /* We can use the operator [] to select which element to choose e.g. [128, 128] has 2 elements */
  22.             int frame_width = it->second["frame_size"][0].as<int>();
  23.             int frame_height = it->second["frame_size"][1].as<int>();
  24.            
  25.             /* Clear the frames vector in case there is some garbage down there */
  26.             animation->m_frames.clear();
  27.            
  28.             /* Iterate trough every frame */
  29.             for (unsigned int i = 0; i < it->second["frames"].size(); i++)
  30.             {
  31.                 /* Fetch the position of the frame in the image */
  32.                 int x = it->second["frames"][i][0].as<int>();
  33.                 int y = it->second["frames"][i][1].as<int>();
  34.  
  35.                 /* Setup an sf::Intrect which is used to define the region of the frame in the image */
  36.                 sf::IntRect rect;
  37.                 rect.left = x;
  38.                 rect.width = frame_width;
  39.                 rect.top = y;
  40.                 rect.height = frame_height;
  41.  
  42.                 /* Save each frame into the frame vector */
  43.                 animation->m_frames.push_back(rect);
  44.             }
  45.  
  46.             /* Save each animation into the animation manager */
  47.             animationManager->addAnimation(animation);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment