My develop environment is:
- Spine 3.6.36 Pro
- Cocos2d-x 3.12 + Spine runtime 3.6.32(The latest version which is smaller than the spine editor version)
I simply export spineboy animation to binary files(atlas + png + skel). I use the code below to load the animation.
spine::SkeletonAnimation * pSpine = spine::SkeletonAnimation::createWithBinaryFile("res/effects/spineboy.skel", "res/effects/spineboy.atlas");
pSpine->setAnimation(0, "run", true);
pSpine->setPosition(size.width / 2, size.height / 2);
this->addChild(pSpine);
It's very very basic using! But the first display is not correct, see the attachment.
It seems that all bones are not positioned but being displayed. How to remove this?
After some debugging, I found this problem may be caused by the executing order of update() and draw(). Which means when the first draw() is called, the first update() is not called yet.
See the "onEnter" code in SkeletonRenderer.cpp and "drawScene" code in CCDirector.cpp
void SkeletonRenderer::onEnter () {
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return;
#endif
Node::onEnter();
update(0); // Added to resolve the problem
scheduleUpdate();
}
I simply add a manual call to update(0) to ensure that all spine stuffs has been initialized before the first draw(). I don't know whether this is the right way to resolve this problem, but it works for me.
It will be nicer if there is a official answer to this problem~