Sorry I wasn't clear enough. As I said earlier I am not sure this is exactly a bug, but more of not clear enough documentation.
According to the documentation:
Invoked every time this entry's animation completes a loop
And this is exactly what happens. Every 1.66 seconds there is OnComplete for Idle animation and every 1.33 seconds there is an OnComplete event for the Jump animation. It is more of a documentation understanding issue on my side.
While reading the documentation I just got the wrong assumption that after SetAnimation(jump) the first OnComplete event will be about the jump animation, not possibly about the previous animation that is fading out in the mix.
triggered T: 0,8725948
On Complete idleT: 1,653958 T since previous: 1,653958 <
---
can occur "randomly" based on the time of the trigger and mix duration
On Complete jumpT: 2,20225 T since previous: 0,5482914
After re-reading the docs and the source code a few times I found out that the OnComplete on every successful loop completion (independent of the fact it fades out, which makes sense now to me). What I would suggest is just a bit of extra clarification about this case in the documentation.
On my side I have the following character logic:
- Idle animation
- Fire animation (sends spine event when the bullet shall leave the muzzle)
And the following (pseudo) code:
CharacterState state;
void SpineAnimationOnComplete(TracEvent event)
{
if (state != CharacterState.Idle) {
spine.SetAnimation(0, "Idle", true);
state = CharacterState.Idle;
}
}
void StartFire()
{
spine.SetAnimation(0, "Fire", false);
state = CharacterState.Fire;
}
void SpineAnimationOnEvent(TrackEntry entry, Spine.Event e)
{
if (e.Data.Name == "Fire") {
SendBulletFromMuzzle();
}
}
In the above case the mix duration was 0.2s and the "Fire" event was sent at 0.48s from the "Fire" animation's start.
Let's assume the following:
Case1 (bad):
T 0.0 -> SetAnimation(Idle) (from startup code)
T 0.8 -> SetAnimation(Fire) (from user pressing fire button and calling StartFire())
T 1.0 -> OnComplete -> from idle, but my state is fire, so I set SetAnimation(idle)
T 1.2 -> mix for Fire->Idle completed (exactly 0.4 seconds after the Fire started, no time for the event to fire)
Case2 (good):
T 0.0 -> SetAnimation(Idle) (from startup code)
T 0.7 -> SetAnimation(Fire) (from user pressing fire button and calling StartFire())
T 0.9 -> mix for Idle->Fire completed (before a new OnComplete event)
T 1.18 -> OnEvent() -> bullet is spawned
T 1.36 -> OnComplete -> from "fire", SetAnimation(Idle)
As you can see this created a race condition where the bullet was not spawned everytime.
This is what I mean by "unexpected" OnComplete. It is not "unexpected" from Spine's point of view. It was "unexpected" from my point of view.
And even though I am not sure gofiguregames is having the same issue, it seems like a potential source of a problem if miscounting the number of loops in a similar way.
P.S. I hope I made it more clear, not more confusing.