Creating and coding enemy animation
Now, let's create a similar spritesheet and data file for the enemy also. All the required files for the enemy frames are provided in the chapter's Resources
folder. If for some reason you are not able to create the spritesheet, the spritesheet and data file that I have used in the book are also provided.
So, once you create the spritesheet for the enemy, it should look something like the following screenshot. Don't worry if the images are shown in the wrong sequence, just make sure that the files are numbered correctly from 1
to 4
and it is in the sequence in which the animations needs to be played.
Now, place the enemy_anim.png
spritesheet and data file in the Resources
folder in the directory, and add the following lines of code in the Enemy.cpp
file to animate the enemy:
//enemy animation CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create("enemy_anim.png"); CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache...