Game Development Reference
In-Depth Information
class frame
{
public:
frame(const math::rectangle& region, float duration)
: m_region(region)
, m_duration(duration)
{}
float Duration() const { return m_duration; }
const math::rectangle& Region() const { return m_region; }
private:
math::rectangle m_region;
float m_duration;
};
The frame data will be configured after loading the sprite sheet and will be considered read-
only at runtime.
4.1.2 Sprite Sheets
A sprite sheet is a single image that contains many frames for a given sprite, each collection
of frames can be thought of as an 'animation', so a sprite sheet may contain different anim-
ations, for example a character sprite would likely contain animations for walking up/left/
right/down, running, jumping, etc. In the case of user interface controls, such as a button, a
spritesheet could contain animations that show when the button is in-focus, pressed or re-
leased.
The sprite sheet will contain the texture and the animation data required for drawing sprites
on screen, it will also own the sprite batch object for the sprite to ensure that all instances of
a given sprite will be batched together.
The sprite sheet will then serve as a factory of sprites, allowing to create as many instances
of a given sprite sheet as we need.
std::shared_ptr<sprite> Create()
{
std::shared_ptr<sprite> newSprite = std::shared_ptr<sprite>(new sprite(*this));
m_sprites.push_back(newSprite);
return newSprite;
}
Search WWH ::




Custom Search