Jump to content

Sprite animation duration


svatopluk
 Share

Recommended Posts

Hello.

I need to run a function when sprite animation is finished. I have tried with this code:

sprite.playAnimation(0, frameCount, false, delay);

setTimeout(function {
...
}, frameCount * delay);

but it's not working. The code is being executed a few seconds after the animation has finished.

I know that this type of construct (setTimeout function) is not desired but I don't know of any other option in this case.

Link to comment
Share on other sites

1 hour ago, svatopluk said:

Hello.

I need to run a function when sprite animation is finished. I have tried with this code:


sprite.playAnimation(0, frameCount, false, delay);

setTimeout(function {
...
}, frameCount * delay);

but it's not working. The code is being executed a few seconds after the animation has finished.

I know that this type of construct (setTimeout function) is not desired but I don't know of any other option in this case.

Javascript questions..awesome.

It would be better if there were a boolean or something that let you know when the animation was finished. I'm not sure that  trying to calculate the "timing" is really going to give you the reaction you want.  Can you post a playground example, and specify what you want to happen? or use alert() as an example. Or here's one of a sprite from the playground search.

http://www.babylonjs-playground.com/#1QIO9T#0

there's a method for sprite called disposeWhenFinishedAnimating. It's used in that example. Not sure what it's disposing, and I dont have the time right now but maybe it could be wrapped in a function that returned a boolean that indicated when the animation was finished. I don't know, kind of a shot in the dark, thats just the closest thing I can see right at this moment.

Link to comment
Share on other sites

disposeWhenFinishedAnimating removes resources when sprite's animation is done.

 

I guess it could be easy to add onAnimationEnd callback to PlayAnimation.Something like:

sprite.playAnimation(0, frameCount, false, delay, function() {});

 

Edit: I did it: http://www.babylonjs-playground.com/#1QIO9T#3

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