riverman_paul

I used Spine-c and wrote my own C++ rendering engine on top of it. My question is, what is the best practice for getting the spine event callbacks back to the interested object? Basically I have a situation like:
class Entity
{
Entity();
void start_spine_animation();
void spine_event_callback(spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event);
};
I want to call myEntity.start_spine_animation() then get control back to the spine_event_callback() when the event fires. However, the event callback is a function pointer which would not be appropriate for an object's member function.

Should I modify Spine-c so that the event callback operates on a pointer to an abstract class that implements the callback function (which would be a common C++ or obj-c way to do it), or handle the control a different way using the original "global" version of the callback function pointer?
riverman_paul
Posts: 7

Nate

TrackEntry has a void* userData field. You can set the listener on the track entry and use userData to get back to the object you care about.
User avatar
Nate

Nate
Posts: 7647

riverman_paul

Ah very good. I'm sorry if I missed this is in the spine-c documentation guide. If not, might be helpful to put in!
riverman_paul
Posts: 7

badlogic

Good suggestion, I've added it to the spine-c doc update issue here Update spine-c docs · #1012
User avatar
badlogic

Mario
Posts: 1084

riverman_paul

What if you're not too concerned with individual tracks, you just want to set the listener for the spAnimationState as a whole? Basically what I'm asking is, is there some way I can set the userData once per game entity and forget about it, rather than every time I set/change the animation for a track?
riverman_paul
Posts: 7

Nate

We could add void* userData to AnimationState, for when people are using AnimationState#listener. What do you think, badlogic?

Also I noticed AnimationState and TrackEntry both have a void* rendererObject, but I don't remember why!?
User avatar
Nate

Nate
Posts: 7647

badlogic

Adding userData to AnimationState makes sense. As for the rendererObject, there was a reason for that, which I forgot. I've opened an issue here [c] Add userData to AnimationState for global callbacks, remove renderObject · #1017
User avatar
badlogic

Mario
Posts: 1084

badlogic

There's actually already a 'userData' on 'spAnimationState', forgot about that.
User avatar
badlogic

Mario
Posts: 1084

Nate

Where? It's only on TrackEntry.
User avatar
Nate

Nate
Posts: 7647

badlogic

Yeah, I'm an idiot. Fixing.
User avatar
badlogic

Mario
Posts: 1084

badlogic

Added userData to spAnimationState.
User avatar
badlogic

Mario
Posts: 1084


Return to Runtimes