mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
C++11 AnimationState listener.
Because 2014.
This commit is contained in:
parent
87a5f683c3
commit
90ec4db279
@ -49,7 +49,7 @@ bool ExampleLayer::init () {
|
||||
skeletonNode = SkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas", 0.6f);
|
||||
skeletonNode->setMix("walk", "jump", 0.2f);
|
||||
skeletonNode->setMix("jump", "run", 0.2f);
|
||||
skeletonNode->setAnimationListener(this, animationStateEvent_selector(ExampleLayer::animationStateEvent));
|
||||
skeletonNode->setAnimationListener(&ExampleLayer::animationStateEvent, this);
|
||||
// skeletonNode->timeScale = 0.3f;
|
||||
skeletonNode->debugBones = true;
|
||||
|
||||
|
||||
@ -63,9 +63,6 @@ SkeletonAnimation* SkeletonAnimation::createWithFile (const char* skeletonDataFi
|
||||
}
|
||||
|
||||
void SkeletonAnimation::initialize () {
|
||||
listenerInstance = 0;
|
||||
listenerMethod = 0;
|
||||
|
||||
ownsAnimationStateData = true;
|
||||
state = spAnimationState_create(spAnimationStateData_create(skeleton->data));
|
||||
state->context = this;
|
||||
@ -117,11 +114,6 @@ void SkeletonAnimation::setMix (const char* fromAnimation, const char* toAnimati
|
||||
spAnimationStateData_setMixByName(state->data, fromAnimation, toAnimation, duration);
|
||||
}
|
||||
|
||||
void SkeletonAnimation::setAnimationListener (Ref* instance, SEL_AnimationStateEvent method) {
|
||||
listenerInstance = instance;
|
||||
listenerMethod = method;
|
||||
}
|
||||
|
||||
spTrackEntry* SkeletonAnimation::setAnimation (int trackIndex, const char* name, bool loop) {
|
||||
spAnimation* animation = spSkeletonData_findAnimation(skeleton->data, name);
|
||||
if (!animation) {
|
||||
@ -153,7 +145,7 @@ void SkeletonAnimation::clearTrack (int trackIndex) {
|
||||
}
|
||||
|
||||
void SkeletonAnimation::onAnimationStateEvent (int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||
if (listenerInstance) (listenerInstance->*listenerMethod)(this, trackIndex, type, event, loopCount);
|
||||
if (listener) listener(this, trackIndex, type, event, loopCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,8 +38,7 @@
|
||||
namespace spine {
|
||||
|
||||
class SkeletonAnimation;
|
||||
typedef void (cocos2d::Ref::*SEL_AnimationStateEvent)(spine::SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount);
|
||||
#define animationStateEvent_selector(_SELECTOR) (SEL_AnimationStateEvent)(&_SELECTOR)
|
||||
typedef std::function<void(spine::SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount)> AnimationStateListener;
|
||||
|
||||
/** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be
|
||||
* played later. */
|
||||
@ -62,7 +61,10 @@ public:
|
||||
void setAnimationStateData (spAnimationStateData* stateData);
|
||||
void setMix (const char* fromAnimation, const char* toAnimation, float duration);
|
||||
|
||||
void setAnimationListener (cocos2d::Ref* instance, SEL_AnimationStateEvent method);
|
||||
template<class _Rx, class _Farg0, class _Arg0> void setAnimationListener (_Rx _Farg0::* const type, _Arg0&& target) {
|
||||
this->listener = std::bind(type, target, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5);
|
||||
}
|
||||
|
||||
spTrackEntry* setAnimation (int trackIndex, const char* name, bool loop);
|
||||
spTrackEntry* addAnimation (int trackIndex, const char* name, bool loop, float delay = 0);
|
||||
spTrackEntry* getCurrent (int trackIndex = 0);
|
||||
@ -76,8 +78,7 @@ protected:
|
||||
|
||||
private:
|
||||
typedef SkeletonRenderer super;
|
||||
cocos2d::Ref* listenerInstance;
|
||||
SEL_AnimationStateEvent listenerMethod;
|
||||
AnimationStateListener listener;
|
||||
bool ownsAnimationStateData;
|
||||
|
||||
void initialize ();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user