Looking at some lines of code from a canvas sprite animation on GitHub, I am curious about how to stop the animations once the sprite has finished.
window.requestAnimFrame = (function(callback) { // Function for handling animation frames
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
function animate() { // Animation loop that draws on the canvas
context.clearRect(0, 0, context.canvas.width, context.canvas.height); // Clearing the canvas
spriteMap.draw(context, 100, 100); // Drawing the sprite
requestAnimFrame(animate); // Running the animation loop
}