Callback when animation complete?

Recommended Posts

Looking at the signature for, 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)?




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


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 ="name")animationReference.isPlaying

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.