seiyria Posted March 2, 2014 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? Link to comment Share on other sites More sharing options...
george Posted March 2, 2014 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 Link to comment Share on other sites More sharing options...
seiyria Posted March 2, 2014 Author 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! Link to comment Share on other sites More sharing options...
kleepklep Posted December 8, 2015 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 Link to comment Share on other sites More sharing options...
Igor Georgiev Posted April 25, 2016 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... Link to comment Share on other sites More sharing options...
MichaelD Posted April 25, 2016 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. Link to comment Share on other sites More sharing options...
Jimaginary Posted April 21, 2017 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? Link to comment Share on other sites More sharing options...
Recommended Posts