seiyria Posted March 2, 2014 Report Share Posted March 2, 2014 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? Quote Link to comment Share on other sites More sharing options...
george Posted March 2, 2014 Report Share Posted March 2, 2014 Hi! Look at the events property of the sprite. There you find onAnimationStart, onAnimationComplete & onAnimationLoopTo 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.isPlayinghttp://docs.phaser.io/Phaser.Animation.html Quote Link to comment Share on other sites More sharing options...
seiyria Posted March 2, 2014 Author Report Share Posted March 2, 2014 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! Quote Link to comment Share on other sites More sharing options...
kleepklep Posted December 8, 2015 Report Share Posted December 8, 2015 Here's the actual callback code if anyone needs it!sprite.animations.currentAnim.onComplete.add(function () { console.log('animation complete');}, this); SP Jimmy and JamesA 2 Quote Link to comment Share on other sites More sharing options...
Igor Georgiev Posted April 25, 2016 Report Share Posted April 25, 2016 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... Quote Link to comment Share on other sites More sharing options...
MichaelD Posted April 25, 2016 Report Share Posted April 25, 2016 It works for me on 2.4.6 I don't see why it shouldn't. Maybe there isn't a currentAnim (an animation playing?) Usually you need to declare this after you start an animation. Quote Link to comment Share on other sites More sharing options...
Jimaginary Posted April 21, 2017 Report Share Posted April 21, 2017 nice! But suppose a sprite had multiple animations added to it. Is there a way in the onComplete callback function to know which animation it was that just completed? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.