The callback gets AnimationState* state
which has a void* rendererObject
field. You can use this to have context for the event. Eg, you could put your instance in rendererObject
, then in the callback cast rendererObject
to your instance and call a method on in.
A similar approach can be used when setting a callback for spTrackEntry
. If the spTrackEntry
owns the data, eg if you allocate a struct for the entry to store various pointers, then you need to set the disposeTrackEntry
function for the spAnimationState
, shown here.
Both approaches are used by spine-cocos2d-iphone and spine-cocos2dx:
https://github.com/EsotericSoftware/spi ... on.cpp#L43
spine-cocos2dx uses C++11 lambas to make spAnimaitonState
event callbacks easier. The end result looks like this:
https://github.com/EsotericSoftware/spi ... le.cpp#L52
Note how the spTrackEntry
callback is done on line 73.
Probably you'd want to build a small system for however you choose to do callbacks, then use that in your game.