spineRunTime for cocos2dx v3 中刪除animation,發現下面寫法會崩潰: json
spine::SkeletonAnimation* animationNode = spine::SkeletonAnimation::createWithFile("explosion/explosion.json", "explosion/explosion.atlas", 1);oop
animationNode->setAnimation(0, "animation", false);rem
animationNode->setPosition(ccp(x,y));get
animationNode->setEndListener( [animationNode] (int trackIndex) {animation
//spTrackEntry* entry = spAnimationState_getCurrent(animationNode->getState(), trackIndex);string
//const char* t_animationName = (entry && entry->animation) ? entry->animation->name : 0;it
//string animationName=t_animationName==0?"":t_animationName;io
//CCLOG("%d end: %s", trackIndex, animationName.c_str());List
animationNode->removeFromParentAndCleanup(true);im
});
因而只好經過加一個延遲來避免崩潰,下面是可用的寫法:
spine::SkeletonAnimation* animationNode = spine::SkeletonAnimation::createWithFile("explosion/explosion.json", "explosion/explosion.atlas", 1);
animationNode->setAnimation(0, "animation", false);
animationNode->setPosition(ccp(x,y));
animationNode->setEndListener( [animationNode] (int trackIndex) {
//spTrackEntry* entry = spAnimationState_getCurrent(animationNode->getState(), trackIndex);
//const char* t_animationName = (entry && entry->animation) ? entry->animation->name : 0;
//string animationName=t_animationName==0?"":t_animationName;
//CCLOG("%d end: %s", trackIndex, animationName.c_str());
animationNode->runAction(CCSequence::create(CCDelayTime::create(0.01),CCRemoveSelf::create(),NULL));
});
或者用completeListener,仍然須要加延遲:
animationNode->setCompleteListener( [animationNode] (int trackIndex, int loopCount) {
//spTrackEntry* entry = spAnimationState_getCurrent(animationNode->getState(), trackIndex);
//const char* t_animationName = (entry && entry->animation) ? entry->animation->name : 0;
//string animationName=t_animationName==0?"":t_animationName;
//CCLOG("%d complete: %s %d", trackIndex, animationName.c_str(),loopCount);
animationNode->runAction(CCSequence::create(CCDelayTime::create(0.01),CCRemoveSelf::create(),NULL));
});