svatopluk Posted August 6, 2016 Share Posted August 6, 2016 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. Quote Link to comment Share on other sites More sharing options...
webGLmmk Posted August 6, 2016 Share Posted August 6, 2016 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 8, 2016 Share Posted August 8, 2016 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() {}); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 8, 2016 Share Posted August 8, 2016 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 webGLmmk and adam 2 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.