So, I'm having an issue with figuring out how to pause and (most importantly) unpause my simulation. When I press play, I call a function called animate(). I only call it once, so naturally inside animate() I call requestAnimationFrame(animate) for it to loop as usual:
function animate() {
idAnimate = requestAnimationFrame(animate);
(...more code...)
}
Note that I'm attibuting the return to idAnimate so I can use it as argument for cancelAnimationFrame(idAnimate) wherever I need it. My problem is that, once I'm able to stop the animation, I cannot unpause it back. I've searched for alternatives, like using a boolean variable like isPaused and only calling requestAnimationFrame when isPaused is false, but as far as I understand when isPaused becames true the animation loop stops and it can no longer test if it's true or not. I only call animate() once, so once it's out of the loop it no longer enters it. No matter how I pause it (either by making isPaused true or calling externally cancelAnimationFrame(idAnimate)), I can't seem to make it go back.
I'd love some insight on this. I hope I was able to make myself clear. Thank you in advance! :)