Creating your first animation
Now that we have a way to load a large amount of images efficiently, we can go further using these images to animate our sprites.
An animation is the simulation of a movement by displaying sequences of static images that will make our brain think that it's looking at a smooth motion.
If you think about it, we already have the knowledge and the tools to create them because for this purpose, we need a sequence of static images that will be displayed in a loop that could be endless or not.
To begin, we need to import the CCAnimation
class, so add the following code to the imports section in GameScene.h
:
#import "CCAnimation.h"
Now let's declare a constant for the number of frames that will take part in the animation by adding the following lines to GameScene.m
after the import
section:
// Number of walk animation frames const int NUM_WALK_FRAMES = 6;
This doesn't need an explanation, as it's just a constant declaration. Now add the following lines at the end of the init...