spineRuntTime for cocos2dx v3,attack播完后回到idle

spineRuntTime for cocos2dx v3,attack播完后回到idle。

_animationNode = spine::SkeletonAnimation::createWithFile("animations/skeleton.json", "animations/skeleton.atlas", 1.0);
_animationNode->setAnimation(0, "idle", true);
_animationNode->setPosition(ccp(x,y));
addChild(_animationNode);

_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);
  if(animationName=="attack"){
    _animationNode->setAnimation(0, "idle", true);
  }
});

 

需要特别注意的是:必须用CompleteListener,而不能用EndListener(会崩溃),参考:https://github.com/EsotericSoftware/spine-runtimes/issues/150

 

posted on 2015-05-08 20:00  wantnon  阅读(294)  评论(0编辑  收藏  举报

导航