How to pause canvas animation made with requestAnimationFrame ? I start animation like this:
Code:
window.requestAnimFrame = (function() {
return w
What you could do is create a variable that stores the state of your animation: paused or unpaused. Change that state every time you click a button. Something like this should work:
var isPaused = false;
window.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
function Start() {
if (isPaused) {
Update();
}
requestAnimFrame(Start);
}
window.onkeydown = function() {
isPaused = !isPaused; // flips the pause state
};
Start();