Skip to content
Advertisement

THREE.JS and buttons for start and pause animation

I try to launch an animation from my THREE.js GUI.

I have two buttons which are “Start” and “Reset” animation. Firstly, when I click on “Start” button, the animation has to launch (the animation is a rotation of a sphere) and the text of this button is set to “Pause“. After the animation is launched, I can click another time to do a pause and stop the animation.

My issue is that I don’t know to handle the rendering of the animation with these clicks and the render() of THREE.JS.

Here is what I have done for the moment :

JavaScript

and for my render() function, I have got :

JavaScript

As you can see, I try to call render() function to start the animation when I click first on startButton but I don’t know to begin from a static sphere (actually, this is the camera which rotates) and, after the click on start, to make it rotate.

Could someone give more informations about this issue ?

Thanks in advance.

Advertisement

Answer

Just return before requestAnimationFrame to pause:

JavaScript

[ https://jsfiddle.net/yr9ogsh8/ ]

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement