[C++] Looking for a tutorial of SKELETON ANIMATION on Cocos2d-x 3.x

its working . i checked on iPhone ios 7.0

Can any one verify me that its also working fine on andriod

plz give the simple code example to implement skeleton animation…

Look in CPPTests, there is a comprehensive example.

i face the issue on cocos2dx v3 android … link all the file but issue is still there!!
Undefine reference
spine::SekeletonAnimation::createWithFile(const* , const*, scale)

Does it work from CPPTests?

thanks alot friend its work…

Please provide help for implementing skeleton animation in cocos2d-x 3.2 with code.
and how we create skeleton animation also ?

This should get you started: http://www.gmtdev.com/blog/2014/09/02/getting-started-with-spine-skeletal-animations-with-cocos2d-x-v3/

That isn’t using the Spine version 1.1 currently in Cocos2d-x v3.2 but the new 2.1 git version, I expect (hope) it will make it into cocos2d-x v3.3 or v3.4 but since you can add it easily, just use the new version.

Note you would need to buy Spine (Essential version will do, $69), or you can use the Cocosstudio Animation utility, it’s free but not quite as advanced.

There are plenty of Spine tutorial videos on Youtube and documentation on the net.

hello…i have problem in spine…
i try to get boundingBox(for collosine) make in spine… under skin as in spineboy jeson file.
but every time i face errors… to access it.
plz help me… thanks

You’re probably better off asking in the spine forums http://esotericsoftware.com/forum/

And give more detail or sample code.

I have covered and ported the game which uses spine animation in by book. On packt’s site there is a blog on skeltal animation written by me which you can access here. [book] Learning Cocos2d-x Game Development: v3.3 Port

Hope this helps!!!

code::**: Rect projectileRect = skeletonNode->boundingBox().intersectsRect(skeletonNode->findSlot("bb"));**

jesonfile:::

“skins”: {
“default”: {
“bb”: {
“bb”: {
“type”: “boundingbox”,
“vertices”: [ 145.86462, 60.16864, 46.875793, 100.647125, -69.445435, 62.195053, -146.72218, -4.293091, -147.08401, -149.57404, 189.17914, -48.34204 ]
}

want to acess jeason file bounding box( for collosin)… .
plz provide guideness…

Hi, i read your book. Can you please show where you run “multiple animation” with spine.

Hmmm… I did a test long time ago where character will go between idle and jump animation… I might still have it somewhere and did through the projects… if I find it ill let you know… cheers!!!

Thanks,

The second thing I was trying to do was to Spawn more enemies using spine… When I load 1 spine object, everything runs well, but when I try to load 2 or more sprites fps drops very fast and the game is unplayable. Can you please also provide an example where you load more spine objects into the scene… Maybe I am doing something wrong. I tryed searching everywhere on the internet for months and they only show how to load 1 spine object…

I used version 3.x of your code.

Here is the code sawpping animations… not sure why it is lagging… are u running on win32… it seems spine has some issues there

///// .cpp

 include "HelloWorldScene.h"


 USING_NS_CC;

CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();

// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();

// add layer as a child to scene
scene->addChild(layer);

// return the scene
return scene;
}


bool HelloWorld::init () {

if (!CCLayerColor::initWithColor(ccc4(255,255,255,255))) return false;

visibleSize = CCDirector::sharedDirector()->getVisibleSize();
gravity = ccp(0, -1);
thrust = ccp(0, 0);
GROUNDLEVEL = 80;


CCSprite* bg = CCSprite::create("tempBg.png");
bg->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));
addChild(bg);

skeletonNode = extension::CCSkeletonAnimation::createWithFile("player.json", "player.atlas");
skeletonNode->setPosition(ccp(visibleSize.width / 4, GROUNDLEVEL));
addChild(skeletonNode);

//skeletonNode->setMix("walk", "jump", 0.1f);
//skeletonNode->setMix("jump", "walk", 0.1f);    
skeletonNode->setAnimation("idle", true);

CCLog("skelTOnNode: width: %f, height: %f", skeletonNode->getContentSize().width, skeletonNode->getContentSize().height);

scheduleUpdate();

setTouchEnabled(true);

return true;
 }

  void HelloWorld::update (float deltaTime) {

thrust.y += gravity.y;	

CCPoint pos = ccp(skeletonNode->getPositionX(),
						  skeletonNode->getPositionY() + thrust.y);

skeletonNode->setPosition(pos);


CCRect playerBBox = skeletonNode->boundingBox();
float pHeight = playerBBox.getMaxY() - playerBBox.getMinY();


if(skeletonNode->getPositionY()<= GROUNDLEVEL){
	CCPoint pos = ccp(skeletonNode->getPositionX(), GROUNDLEVEL);
	skeletonNode->setPosition(pos);
	thrust.y = 0; 
}else if (skeletonNode->getPositionY() + pHeight >= visibleSize.height){
	CCPoint pos = ccp(skeletonNode->getPositionX(), visibleSize.height - pHeight);
	skeletonNode->setPosition(pos);
	thrust.y = 0; 
}

if(skeletonNode->getPositionY() <= GROUNDLEVEL){
	
	if(mAnimState != kAnimStateWalk){
		skeletonNode->setAnimation("walk", true);
		mAnimState = kAnimStateWalk;
	}

}else{
	
	if(mAnimState != kAnimStateJump){	
		skeletonNode->setAnimation("jump", false);
		mAnimState = kAnimStateJump;
	}
}

//CCLog("CurrentAnimaName : %s", skeletonNode->states[0]->animation->name);
//CCLog("ypos: %f", skeletonNode->getPositionY());
CCLog("boundingBox: x: %f, y: %f", skeletonNode->boundingBox().getMaxX(),skeletonNode->boundingBox().getMaxY());
 }

 void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent){

CCTouch* touch = (CCTouch*)pTouches->anyObject();

CCPoint touchLocation = touch->getLocationInView();
touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);

if(touchLocation.x < visibleSize.width /2){

	thrust.y = 15;	
}
}

//// .h file

 #ifndef __HELLOWORLD_SCENE_H__
 #define __HELLOWORLD_SCENE_H__

 #include "cocos2d.h"
  #include <spine/spine-cocos2dx.h>
  using namespace cocos2d;
  using namespace extension;


  enum AnimState 
  {
kAnimStateNone = 0,
kAnimStateWalk ,
kAnimStateJump
 };


 class HelloWorld : public cocos2d::CCLayerColor
 {
 public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();  

extension::CCSkeletonAnimation* skeletonNode;

// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::CCScene* scene();

CCSize visibleSize;
CCPoint gravity;
CCPoint thrust;
float GROUNDLEVEL; 
AnimState mAnimState;

// a selector callback
void menuCloseCallback(CCObject* pSender);
virtual void update (float deltaTime);
virtual void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);

// implement the "static node()" method manually
CREATE_FUNC(HelloWorld);
};

#endif // __HELLOWORLD_SCENE_H__

//// output

1 Like

Thank you very much for the code, I will study it tonight.

In the meantime can you please try to write two write code that spawns 2 and more spine objects and see if the framerate does not drop.

I do not think its win32 that has the problem. I tested on android and windows phone. I was about to quit cocos2d-x and go with unity.

Hi!. Unfortunately my schedule is very tight … but if I get time Ill definitely see what the issue is … best wishes

Hi! I know this is unrelated topic, but it was the fastest way to reach you…

In your new “android/unity” book, you did not provide the following images bg_snow1.png and bg_snow2.png.

I extracted all the zip files and didn’t find those two images. Could you please provide a location of where I can get hold on them please.

Thanks!

You can PM him too.