callback function for Spine events

Hi guys, I’ve implemented events and other features in Spine [1] that have callbacks. Eg, in the generic C runtime, the AnimationState class has a C function pointer [2] so you can get a callback on animation start, end, etc. For the cocos2dx runtime, I’d like to do something nicer that fits in better with cocos2dx and C**. I took a crack at it and using it looks like this .
What do you think? Is there a better way? There is std::function with C**11. I’m supporting cocos2dx 2.x so I’m not sure if I should use that?

1: Spine, a 2D skeletal animation tool: http://esotericsoftware.com/
2: AnimationState’s C callback: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-c/include/spine/AnimationState.h#L50
3: CCSkeletonAnimation’s C++ callback: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-cocos2dx/src/spine/CCSkeletonAnimation.h#L68
4: CCSkeletonAnimation’s callback example: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-cocos2dx/example/Classes/ExampleLayer.cpp#L25

Hi.
I’ve found the way you setup the listener a bit complicated, I would rather have one method for each event type.

If we changed to multiple methods it would break people’s code for not too much gain. You could write a small utility class that dispatches the event as needed. The runtime API is pretty low level because it needs to be flexible enough to cover many use cases. It is expected that users will write a thin layer over the API to integrate how they are using it in their particular game.

It is what I’m doing, will probably make it public when it’s done, it feels more cocos-like than the spine way. Although I’m somewhat late to the discussion.

Likely you are better at making it cocos2dx-y than I. :slight_smile: If you’d like to contribute it to Spine and feel it is worth the API breakage, maybe we should merge it in.

I would love to see this code, the team over at Trese Brothers is a huge fan of doing spine the Cocos2d-x way =)

Nathan — I think if you are targeting 2.x you should not use C11 because it isn’t supported on the Blackberry yet?
I believe that 2.x is not C
11

Did I use C++11?

I prefer to use C++11 :slight_smile:

I just need it. Thanks.:slight_smile: