JohnM Posted June 25, 2018 Share Posted June 25, 2018 Hello all, I am making a project and i need to play animations on a button click. but for some reason after the animation is played the first time it will never play again. I have been able to replicate the basics in a PG - https://playground.babylonjs.com/indexStable.html#V19ZT2 if you open console and enter window.startAnim.restart() then watch the animation play. then enter window.startAnim.reset(); it will reset, if you then do the restart command again. nothing will happen. why is this? also the version of babylon i am using (i cant find a version number?) has scene.Animatables where it seems all of the animatables (which to my understanding control the animations) are stored. and once the animation is played, it seems the animabable in scene.Animatables is deleted. however in the PG i cant find this variable so i assume its been changed since? however the outcome is the same still. hope this makes sense!! many thanks Quote Link to comment Share on other sites More sharing options...
Guest Posted June 25, 2018 Share Posted June 25, 2018 Hello and welcome! if your animation is not in loop mode, as soon as it is finished it will be removed from the active animation and you won't be able to play it again (consider it disposed if you prefer) Quote Link to comment Share on other sites More sharing options...
JohnM Posted June 25, 2018 Author Share Posted June 25, 2018 ok that makes sense. so if i need to replay it but i dont want it to instantly loop, how do i go about that? i also preferably dont want to create a new animatable each time either. i wondered about having an onanimationend function but i guess it wouldnt end in loop mode untill i tell it to stop / pause? Quote Link to comment Share on other sites More sharing options...
Guest Posted June 25, 2018 Share Posted June 25, 2018 I would go with an onanimationend and just call pause inside it Quote Link to comment Share on other sites More sharing options...
JohnM Posted June 26, 2018 Author Share Posted June 26, 2018 ok so my next question would be, i was using beginDirectAnimation because it creates a new Animatable for each animation as i need to control each animation separately. it seems beginDirectAnimation doesnt have onAnimationEnd (from what i can see) so what would be the next best thing to do to accomplish both needs? many thanks. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 26, 2018 Share Posted June 26, 2018 The doc is not completely up to date http://doc.babylonjs.com/api/classes/babylon.scene#begindirectanimation Quote Link to comment Share on other sites More sharing options...
JohnM Posted June 27, 2018 Author Share Posted June 27, 2018 ok so thats what i assumed / hoped was implemented (like the others) but i feel like im doing something wrong as the function doesnt seem to be called? heres my PG Quote Link to comment Share on other sites More sharing options...
Guest Posted June 27, 2018 Share Posted June 27, 2018 ha! rats!!! the onAnimationEnd is not called when loop is true Sorry! I forgot about that. So in your case I guess the best option is to recreate an animation Quote Link to comment Share on other sites More sharing options...
Guest Posted June 27, 2018 Share Posted June 27, 2018 Or...I can add a new parameter to the Animatable class to prevent it from disposing automatically on end? Quote Link to comment Share on other sites More sharing options...
JohnM Posted June 28, 2018 Author Share Posted June 28, 2018 the second option would be more beneficial i think Quote Link to comment Share on other sites More sharing options...
Guest Posted June 28, 2018 Share Posted June 28, 2018 Stay tune..working on it Quote Link to comment Share on other sites More sharing options...
Guest Posted June 28, 2018 Share Posted June 28, 2018 Here we are: https://github.com/BabylonJS/Babylon.js/pull/4632/commits/a5615208544e9af748ec6446512b393fae984bc1#diff-28f79c6fd37f64932a4be6efccb1132dR15 Dad72 1 Quote Link to comment Share on other sites More sharing options...
JohnM Posted July 2, 2018 Author Share Posted July 2, 2018 awesome, thank you! 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.