How to animate sprites
The Untold Engine supports sprites animation. The engine represents a sprite animation as a U4DEngine::U4DSpriteAnimation object.
Pre-requisite
A U4DSpriteAnimation object requires that you have successfully created a U4DEngine::U4DSprite object with its corresponding spritesheet, as shown in lines 1-6. If you need a refresher, please see the following article.
Step 1. Load animation sprites
Once a spritesheet has been loaded into a U4DEngine::U4DSpriteLoader and a U4DEngine::U4DSprite has been created, you must load the sprites that will be part of the animation into a U4DEngine::SPRITEANIMATIONDATA structure, as shown in line 7.
In this example, the sprites that will be part of the animation are:
spaceinvaderoctopus1.png
spaceinvaderoctopus2.png
These sprites are highlighted in the spritesheet below:
Line 8 provides a delay interval for the animation. Basically, it determines how fast to play the animation.
Create Sprite Animation Object
Once the U4DEngine::SPRITEANIMATIONDATA structure has the corresponding sprites and a delay value, a U4DEngine::U4DSpriteAnimation object is created using the structure and sprite object as parameters. See line 9.
Finally, the sprite animation object is started by calling its play() method, as shown in line 10.
Here is the result:
Last updated