Hi, I noticed that I had some weird things happening when attaching listeners to SkeletonClipNode for PLAYBACK_COMPLETE event.
I quickly realized that when triggering the event for one animated mesh, ALL the listeners across the cloned meshes were called.
That’s when I took a look at the animator.clone function that I understood:
public function clone():IAnimator
{
/* The cast to SkeletonAnimationSet should never fail, as _animationSet can only be set
through the constructor, which will only accept a SkeletonAnimationSet. */
return new SkeletonAnimator(_animationSet as SkeletonAnimationSet, _skeleton, _forceCPU);
}
You don’t clone the animation set…
Now I couldn’t help but notice that classes that implement IAnimator are also event dispatchers…
So I modified this code in AnimationClipState…
Before:
private function notifyPlaybackComplete():void
{
_animationClipNode.dispatchEvent(_animationStatePlaybackComplete ||= new AnimationStateEvent(AnimationStateEvent.PLAYBACK_COMPLETE, _animator, this, _animationClipNode));
}
After:
private function notifyPlaybackComplete():void
{
_animationStatePlaybackComplete ||= new AnimationStateEvent(AnimationStateEvent.PLAYBACK_COMPLETE, _animator, this, _animationClipNode);
if(_animator is IEventDispatcher)
(_animator as IEventDispatcher).dispatchEvent(_animationStatePlaybackComplete);
_animationClipNode.dispatchEvent(_animationStatePlaybackComplete);
}
And now I just add my PLAYBACK_COMPLETE listener to the animator instead of doing it for every single animation node…