标签:
效果都是根据以下测试代码来说的,可能有些不太准确
setStartListener (const StartListener& listener)
StartListener原型
typedef std::function<void(int trackIndex)>StartListener;
效果:如果一个track中有两个以上的动作,那么第二个以后的各个动作开始是会调用StartListener
setEndListener (const EndListener& listener)
EndListener原型
typedef std::function<void(int trackIndex)>EndListener;
效果:如果动画只播放一次,那么播放结束先调用CompleteListener,然后调用EndListener
setCompleteListener (const CompleteListener& listener)
CompleteListener原型
typedef std::function<void(int trackIndex,int loopCount)>CompleteListener;
效果:如果动画循环播放,那么每个循环结束都会调用CompleteListener这个函数
setEventListener(const EventListener& listener)
EventListener原型
typedef std::function<void(int trackIndex, spEvent* event)>EventListener;
效果:这个需要在spine里做动画的时候在某一帧添加event时间,还没有测试,先不多说
setTrackStartListener (spTrackEntry* entry, const StartListener& listener)
setTrackEndListener (spTrackEntry* entry, const EndListener& listener)
setTrackCompleteListener (spTrackEntry* entry, const CompleteListener& listener)
setTrackEventListener (spTrackEntry* entry, const EventListener& listener)
//add a spine animation
auto juese1 =SkeletonAnimation::createWithFile("juese1/juese1.json","juese1/juese1.atlas");
/************************************************************************/
/* 两个都是true,第一个动画播放一次,第二个动画循环播放
/* 第一个true第二个false,两个动画都是只播放一次
/* 两个都是false,两个动画都只播放一次
/* 第一个false第二个true,第一个动画播放一次,第二个动画循环播放
/* 总结:如果有两个动画,不管第一个动画的循环是true还是false,都只播放一次,第二个动画是true就循环是false就不循环
/* 如果有n(n > 2)个动画,那么前(n - 1)个动画的循环是不起作用的都是只播放一次,最后一个动画的循环起作用
/************************************************************************/
juese1->setAnimation(0,"putonggongji",true);
juese1->addAnimation(0,"beiji",true);
juese1->addAnimation(0,"daiji",true);
juese1->setSkin("juese1");
juese1->setScale(0.7f);
juese1->setPosition(Vec2(450,200));
this->addChild(juese1);
juese1->setStartListener([=](int trackIndex){
auto entry = spAnimationState_getCurrent(juese1->getState(), trackIndex);
constchar* animationName =(entry && entry->animation)? entry->animation->name :0;
log("track start: %d, animation name: %s", trackIndex, animationName);
});
juese1->setEndListener([=](int trackIndex){
auto entry = spAnimationState_getCurrent(juese1->getState(), trackIndex);
constchar* animationName =(entry && entry->animation)? entry->animation->name :0;
log("track end: %d, animation name: %s", trackIndex, animationName);
});
juese1->setCompleteListener([=](int trackIndex,int loop){
auto entry = spAnimationState_getCurrent(juese1->getState(), trackIndex);
constchar* animationName =(entry && entry->animation)? entry->animation->name :0;
log("track complete: %d, loop: %d, animation name: %s", trackIndex, loop, animationName);
});
部分log输出
track complete:0, loop:1, animation name: putonggongji
track end:0, animation name: putonggongji
track start:0, animation name: beiji
track complete:0, loop:1, animation name: beiji
track end:0, animation name: beiji
track start:0, animation name: daiji
track complete:0, loop:1, animation name: daiji
track complete:0, loop:2, animation name: daiji
track complete:0, loop:3, animation name: daiji
track complete:0, loop:4, animation name: daiji
track complete:0, loop:5, animation name: daiji
track complete:0, loop:6, animation name: daiji
标签:
原文地址:http://www.cnblogs.com/iamxiaolei/p/5666812.html