Game Development Reference
In-Depth Information
explicit animation(const std::wstring& name)
: m_name(name)
, m_time(0.f)
, m_currentFrame(0)
{ }
frame& AddFrame(const math::rectangle& region, float duration)
{
frame f(region, duration);
m_frames.push_back(f);
return m_frames.back();
}
bool& Loop() { return m_loop; }
const frame& Frame(int index) const { return m_frames[index]; }
const std::wstring& Name() const { return m_name; }
size_t FrameCount() const { return m_frames.size(); }
private:
std::wstring m_name;
float m_time;
bool m_loop;
std::vector<frame> m_frames;
size_t m_currentFrame;
event_handler<animation&> m_onAnimationFinished;
};
The animation class will hold the information required to perform a sprite's animation. In
order to support sprite instancing, the animation behavior will not be implemented as part
ofthisclass.Instead,wewillhaveaspecialized objectwhoseresponsibility willbetokeep
the animation state for a sprite.
4.1.1.1 Animation Track
In order to support sprite instancing, we introduce a class that will perform the animation
based on the sprite's animation data, we can think of the sprite's animation data as read-
only, while the animation track object is a live object that will advance a sprite instance's
animation frames.
class animation_track
{
public:
explicit animation_track(const animation& anim)
: m_animation(anim)
, m_currentFrame(0)
, m_time(0.f)
{}
Search WWH ::




Custom Search