• Runtimes
  • [Cocos2d-x 3.0] Catch event in Runtimes

Hi all,

I have a problem when catch an event from Spine.
When the event was fired, i caught it but Event Data is NULL, i can not get name, string value or anything else.

This is my code:

_skeletonGo = SkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas");
_skeletonGo->setAnimation(1, "test", false);
_skeletonGo->setAnimationListener(this, animationStateEvent_selector(HelloWorld::onAnimationStateEvent));
void HelloWorld::onAnimationStateEvent(int trackIndex, spEventType type, spEvent* event, int loopCount) {
    log("event"); // i debug this line and the event param is NULL
//    std::string name = event->stringValue;
//    if (name.compare("go") == 1) {
//        log("GO!");
//    }
}

Please give me the solution for this problem, thank so much 🙂

Related Discussions
...

Did you check to see what type is? If it's not SP_ANIMATION_EVENT, I don't think event will be anything.

yeah, but all of param's value in onAnimationStateEvent() method will be default value.

trackIndex : 9628000
type : ANIMATION_END
event : not NULL but it's properties is NULL
loopCount : 235520

Which version of cocos2d-x are you using?

As the title, i used cocos2d-x version 3.0 🙁

Of course, silly me. My apologies.

I'm not sure if you are aware, but the runtime has evolved quite a bit since the stock version that came with cocos2d-x 3.0. For instance, IK support has been added since then. Additionally, the animation listener has been broken out into 4 listeners plus 4 track listeners (one for each type of event).

I tried to look at the runtime files in the v3.0 release and couldn't find why you would get those values sent to your animation listener. At first glance, at least, it looks like every time the animation listener is called with the ANIMATION_END event type, the event parameter is null and the loopCount is 0. event is only non-null, if type is ANIMATION_EVENT.

Is the spineboy.json you're using the one that ships with cocos2d-x, or with a more recent version of Spine? Or have you modified it? What I'm getting at here, is that you should double check that the animation has an Event timeline.

You should use the latest runtimes, not the extremely old version packaged with cocos2d-x.

Thank you very much.

Perhaps i will try with the latest version of cocos2d-x (v 3.2), may be it work 🙂

Actually, v3.2 is also using a fairly old version of the runtime. If you want to update to the latest, you can clone the git repository and replace the files in cocos/editor-support/spine/ with the ones from the spine-c AND the spine-cocos2dx runtimes. Then make sure that the files are added to the project.

Oh, I see. Thanks toojuice 🙂