If you add an animation with a delay which is less than the previous animations length it will not take the previous animations duration into account. Essentially the if statement is the wrong way around in spAnimationState_addAnimation()
spTrackEntry* spAnimationState_addAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/[i]bool[/i]/loop,
float delay) {
_spAnimationState* internal = SUB_CAST(_spAnimationState, self);
spTrackEntry* last;
spTrackEntry* entry = internal->createTrackEntry(self);
entry->animation = animation;
entry->loop = loop;
entry->endTime = animation->duration;
last = _spAnimationState_expandToIndex(self, trackIndex);
if (last) {
while (last->next)
last = last->next;
last->next = entry;
} else
self->tracks[trackIndex] = entry;
// Original: if (delay <= 0) {
if (delay >= 0) {
if (last)
delay += last->endTime - spAnimationStateData_getMix(self->data, last->animation, animation);
else
delay = 0;
}
fabs(delay); //may not be needed?
entry->delay = delay;
return entry;
}
I understand you can have negative delays.
Further clarification:
Animation A
- length 2 seconds
Animation B
- length 2 seconds
spAnimationState_setAnimationByName( animState,/[i]track[/i]/ 0, "Animation A",/[i]loop[/i]/ false );
spAnimationState_addAnimationByName( animState,/[i]track[/i]/ 0, "Animation A",/[i]loop[/i]/ false, 1.f);
This will play Animation A
then half way through it will play Animation B
. From the documentation, it should only do this if the delay is negative
it doesn't seem this solution is 100% correct
correct code:
spTrackEntry* spAnimationState_addAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/[i]bool[/i]/loop,
float delay) {
_spAnimationState* internal = SUB_CAST(_spAnimationState, self);
spTrackEntry* last;
spTrackEntry* entry = internal->createTrackEntry(self);
entry->animation = animation;
entry->loop = loop;
entry->endTime = animation->duration;
last = _spAnimationState_expandToIndex(self, trackIndex);
if (last) {
while (last->next)
last = last->next;
last->next = entry;
} else
self->tracks[trackIndex] = entry;
if (delay <= 0) ) {
if (last)
delay += last->endTime - spAnimationStateData_getMix(self->data, last->animation, animation);
else
delay = 0;
}
else
{
if (last)
delay += last->endTime + spAnimationStateData_getMix(self->data, last->animation, animation);
else
delay = 0;
}
}
entry->delay = delay;
return entry;
}
However this highlights an issue with events. If an event has fired, it will fire again at the end of the first animation