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

Coding the player walk cycle


If you want to test the animations in the current project itself, add the following to the HelloWorldScene.h file first:

#include <spine/spine-cocos2dx.h>

Include the spine header file and create a variable named skeletonNode of the CCSkeletalAnimation type:

extension::CCSkeletonAnimation* skeletonNode;

Next, we initialize the skeletonNode variable in the HelloWorldScene.cpp file:

    skeletonNode = extension::CCSkeletonAnimation::createWithFile("player.json", "player.atlas", 1.0f);
    skeletonNode->addAnimation("runCycle",true,0,0);
    skeletonNode->setPosition(ccp(visibleSize.width/2 , skeletonNode->getContentSize().height/2));
    addChild(skeletonNode);

Here, we give the two data files into the createWithFile() function of CCSkeletonAnimation. Then, we initiate it with addAnimation and give it the animation name we gave when we created the animation in Spine, which is runCycle. We next set the position of the skeletonNode; we set it right above...