sts2055

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);
node->setPosition(pTouch->getLocation());
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?
sts2055
  • Mesajlar: 3

Nate

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.
http://esotericsoftware.com/spine/files ... iagram.png
Kullanıcı avatarı
Nate

Nate
  • Mesajlar: 12208

sts2055

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:
#ifndef _EXAMPLELAYER_H_
#define _EXAMPLELAYER_H_

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

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

CREATE_FUNC (ExampleLayer);
private:
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();
scene->addChild(ExampleLayer::create());
return scene;
}

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

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

addSkeletonAnimationAt(pTouch->getLocation());
}

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


Dön Runtimes