Jump to content

Play animations on a html5 button


Recommended Posts

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 


then watch the animation play. then enter


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

Link to comment
Share on other sites

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)


Link to comment
Share on other sites

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? 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

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.

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.


  • Recently Browsing   0 members

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