Jump to content

AnimatedSprite single pass


jay3sh
 Share

Recommended Posts

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?

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...