Game Development Reference
In-Depth Information
4.1S PRITES
A sprite is a 2D image used to represent entities in games, typically animated to simulate
someformofmotion,likeacharacterwalkingortoachievecertainspecialeffects,likewater
orfire.Spritescanbeusedtocreateuserinterfacesaswell,wecancreatespritesforbuttons,
knobs,elementsofaradar,inputcursor,andmanyotheruserinterfaceelementsthatwemay
want to make dynamic and visually pleasing.
Sprites as a construct for user interfaces has the advantage that it gives artists a great deal
of control over the look and feel of the UI, it is also painless to get a placeholder control in
place that meets all the requirements, but may lack detailed animation frames. The disad-
vantages are that the overall video memory cost is higher, and that it may represent a signi-
ficant amount of work for artists if the user interface is extensive or highly detailed.
Whileaspritebasedapproachmaynotyieldthebestresultsintermsofproductionperform-
ance, it serves as an introduction to a more advanced system of animation using timelines,
key frames, transformations and interpolation curves to create complex animations, such a
system is truly powerful as long as it has an authoring tool to go along with it. For the scope
of this topic and the example code, we will use sprites to create visually pleasing controls.
In the system we will implement a sprite is the entity that is animated and drawn on-screen.
Each sprite is an instance, this means each sprite will keep its own animation state, two in-
stances may be playing two different animations at the same time, yet the underlying data is
the same. This avoid duplication of assets in memory, as long as the same sprite sheet is not
loaded more than once.
4.1.1 Animation
A sprite's animation will be defined by specifying regions of a sprite sheet, each region we
specify will be an animation frame and will be visible on-screen for some specified amount
of time. This gives us the flexibility of creating sprites of varying sizes.
class animation
{
public:
animation()
: m_time(0.f)
, m_currentFrame(0)
{}
Search WWH ::




Custom Search