jay3sh Posted November 16, 2017 Share Posted November 16, 2017 Hi, I was trying to make my AnimatedSprite run only once. Initially I thought it could be achieved by setting `loop` to `false` and manually calling `play()`. However that worked only first time. For instance, I wrote code to run the animation once when mouseover. Later on when the animation is over I would take my mouse elsewhere and then bring it back over the sprite to trigger animation again, but this time it wouldn't play. After lot of experimentation I figured out that I have to call `gotoAndStop(0)` in the `onComplete` callback to achieve what I wanted. let animSprite; // Load animSprite animSprite.loop = false; animSprite.gotoStop(0); animSprite.onComplete = function () { animSprite.gotoAndStop(0); }; animSprite.play(); Is this the right way to achieve single-pass animation? ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted November 16, 2017 Share Posted November 16, 2017 Sources:https://github.com/pixijs/pixi.js/blob/dev/src/extras/AnimatedSprite.js#L75 Here it is, compiled into docs:https://pixijs.download/v4.6.1/docs/PIXI.extras.AnimatedSprite.html#loop Quote Link to comment Share on other sites More sharing options...
botmaster Posted November 16, 2017 Share Posted November 16, 2017 You can also extend the object into your own custom class and simply add a playOnce() method in there (that's what I do), less redundancies! 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.