I am trying to add multiple SkeletonAnimations, but run into the following problem:
When adding the CCSkeletonAnimation node to the scene it draws and runs just fine.
But when I try to add the same node again, the first node disappears and only the second node is drawn and animated.

Here the function that creates the animations:
void MyLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
CCTouch* pTouch = static_cast<CCTouch*>(pTouches->anyObject());
CCSkeletonAnimation* node = CCSkeletonAnimation::createWithFile("unit.json", "unit.atlas");
node->setAnimation(0, "walking", true);
addChild(node );
Adding multiple nodes in the same function works correctly, however, the above problem occurs when calling the function again.

I suspect that some of the data is shared internally, but what do I need to set in order to duplicate the node?
  • Mesajlar: 3


Your code should create two completely separate SkeletonAnimations. They won't share any information. Not sure why only one would render! Can you modify ExampleLayer in spine-cocos2dx to show the problem?

Note it would be better to load the SkeletonData once, then create the SkeletonAnimations with that. This way the nodes share the skeleton and animation data, which doesn't have to be loaded multiple times. ... iagram.png
Kullanıcı avatarı

  • Mesajlar: 12208


I tried it in ExampleLayer and it worked flawlessly.
Turns out the problem had to do with the z-Order of the Sprite. Adding the animation to the correct layer fixed things.

Thank you for the quick help Nate!

Here the test code if someone is interested:

#include "cocos2d.h"
#include <spine/spine-cocos2dx.h>

class ExampleLayer: public cocos2d::CCLayer {
static cocos2d::CCScene* scene ();
virtual bool init ();

CREATE_FUNC (ExampleLayer);
virtual void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
void addSkeletonAnimationAt(cocos2d::CCPoint location);

#endif // _EXAMPLELAYER_H_
#include "ExampleLayer.h"
#include <iostream>
#include <fstream>
#include <string.h>

using namespace cocos2d;
using namespace spine;
using namespace std;

CCScene* ExampleLayer::scene () {
CCScene *scene = CCScene::create();
return scene;

bool ExampleLayer::init () {
if (!CCLayer::init()) return false;
return true;

void ExampleLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
CCTouch* pTouch = static_cast<CCTouch*>(pTouches->anyObject());


void ExampleLayer::addSkeletonAnimationAt(cocos2d::CCPoint location)
CCSkeletonAnimation* skeletonNode = CCSkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas");
skeletonNode->setAnimation(0, "walk", true);
  • Mesajlar: 3

Dön Runtimes