AnimationClipState making shared nodes dispatch PLAYBACK_COMPLETE events…

Software: Away3D 4.x

Kicker, Member
Posted: 04 May 2017 05:39 AM   Total Posts: 52

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_animatorthis_animationClipNode));

After:

private function notifyPlaybackComplete():void
{
    _animationStatePlaybackComplete 
||= new AnimationStateEvent(AnimationStateEvent.PLAYBACK_COMPLETE_animatorthis_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…

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X