seiyria

Callback when animation complete?

Recommended Posts

Looking at the signature for AnimationManager.play(name, frameRate, loop, killOnComplete), there doesn't appear to be a way to run a callback when an animation completes. Is there some other way to do this? If not, would it make sense to change this function to accept a callback (which could be sprite.kill)?

 

edit:

 

slightly unrelated, but there also doesn't appear to be a way to check if a sprite is animating except to check if it's currentFrame.index === original frame. Is that the right way to check it?

Share this post


Link to post
Share on other sites

Hi! 

Look at the events property of the sprite. There you find onAnimationStart, onAnimationComplete & onAnimationLoop

To check for a running animation use isFinished, isPaused, isPlaying on the animation instance itself (you get that reference to the animation when you call play)

animationReference = sprite.animations.play("name")animationReference.isPlaying

http://docs.phaser.io/Phaser.Animation.html

Share this post


Link to post
Share on other sites

Hey, cool! I guess I was initially confused because I wasn't sure where to look in the docs and it seemed like so many other things were callback-based, that this should be too. I see now, though. Thanks!

Share this post


Link to post
Share on other sites
On 12/7/2015 at 0:22 AM, kleepklep said:

Here's the actual callback code if anyone needs it!

 


sprite.animations.currentAnim.onComplete.add(function () {	console.log('animation complete');}, this);

Doesn't work on Phaser 2.4.6...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   1 member