예제 #1
0
void SpriteAnimationManager::init() {
	XMLFile doc("data/config/spriteAnimations.xml");
	
	XMLElement *animationElement = doc.FirstChildElement("spriteAnimations").FirstChildElement("animation").ToElement();
	while(animationElement) {
		std::string name = animationElement->Attribute("name");
		std::vector<SpriteAnimation> animation;
		
		XMLElement *framesElement = animationElement->FirstChildElement("frames");
		while(framesElement) {
			std::vector<u16> frames;
			u16 delay = framesElement->IntAttribute("delay");
			
			XMLElement *frameElement = framesElement->FirstChildElement("frame");
			while(frameElement) {
				frames.push_back(frameElement->IntAttribute("id"));
				
				frameElement = frameElement->NextSiblingElement("frame");
			}
			
			animation.push_back(SpriteAnimation(frames.size(), frames, delay));
			
			framesElement = framesElement->NextSiblingElement("frames");
		}
		
		spriteAnimations[name] = animation;
		
		animationElement = animationElement->NextSiblingElement("animation");
	}
}
예제 #2
0
/**
 * \brief Adds a new animation to this animation set.
 *
 * This function is called while loading the animation set.
 *
 * \param animation_name Name of this animation.
 * \param animation_data Properties of the animation to create.
 */
void SpriteAnimationSet::add_animation(
    const std::string& animation_name,
    const SpriteAnimationData& animation_data) {

  std::string src_image = animation_data.get_src_image();
  uint32_t frame_delay = animation_data.get_frame_delay();
  int frame_to_loop_on = animation_data.get_loop_on_frame();
  std::vector<SpriteAnimationDirection> directions;

  // Create directions
  for (const SpriteAnimationDirectionData& direction: animation_data.get_directions()) {

    Size size = direction.get_size();
    max_size.width = std::max(size.width, max_size.width);
    max_size.height = std::max(size.height, max_size.height);
    max_bounding_box |= direction.get_bounding_box();

    directions.emplace_back(direction.get_all_frames(), direction.get_origin());
  }

  animations.emplace(
    animation_name,
    SpriteAnimation(src_image, directions, frame_delay, frame_to_loop_on)
  );
}
예제 #3
0
void Sprite::addAnimation(SpriteAnimation animation) {
	m_animations.push_back(SpriteAnimation(animation.size, animation.tabAnim, animation.delay));
}
예제 #4
0
SpriteAnimId SpriteSheet::AddAnimation()
{
	SpriteAnimId animId = ion::GenerateUUID64();
	m_animations.insert(std::make_pair(animId, SpriteAnimation()));
	return animId;
}
예제 #5
0
Animation::Animation(const char *filename, std::string name, u16 delay, std::vector<u16> frames, u16 frameWidth, u16 frameHeight) : Sprite(filename, frameWidth, frameHeight) {
	m_name = name;
	
	addAnimation(SpriteAnimation(frames.size(), frames, delay));
}