- Modifié
Listening for Spine Events in Phaser 3
I am having trouble listening for events generated in Spine in Phaser 3. The Phaser 3 implementation is not maintained by esoteric, but maybe someone has an example in JavaScript of an event listener that would work with Phaser 3. Does anyone know how to get it to work?
The event I am trying to hook shows up fine in Spine animation, and in the exported JSON, but nothing I do seems to work for listening to the event firing.
This doesn't work:
spine_Animation01.on(‘middle-of-the-loop’, (spine) => {
console.log(‘Middle of the Loop’)
})
But this works:
spine_Animation01.on(‘complete’, (spine) => {
console.log(‘Loop Completed’)
})
I posted in more detail on the Phaser forums, but have not got a working answer yet: https://phaser.discourse.group/t/how-do-you-listen-for-custom-spine-generated-events/5342
I couldn't find documentation for Phaser's Spine integration, but it looks like the on()
function allows you to specify the type of event you want to listen for. When you queue an animation, there are different life-time events that can happen. One of them is an event that you keyed in the editor being fired. The corresponding callback you can pass to on()
is likely called "event"
, see AnimationStateListener
However, I'm not sure what type spine
is and if it gives access to the event data, e.g. it's name or any value associated with the event.
this.spineGameObject.animationState.addListener({
event: (trackEntry: TrackEntry, event: any) => {
console.log(event.data.name);
}
});