Book Image

Learning Cocos2d-x Game Development

By : Siddharth Shekar
Book Image

Learning Cocos2d-x Game Development

By: Siddharth Shekar

Overview of this book

Table of Contents (19 chapters)
Learning Cocos2d-x Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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...