From 64389a4278c14041b85f9aaae0c7295cd890362f Mon Sep 17 00:00:00 2001 From: CookieShade Date: Tue, 26 Jul 2016 00:33:04 +0200 Subject: [PATCH] Simplify animation system Now only supports one animation callback running at any given time. --- BETA.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/BETA.js b/BETA.js index 3b17c63..70e94fb 100644 --- a/BETA.js +++ b/BETA.js @@ -593,18 +593,17 @@ //------------ANIMATION SYSTEM------------\\ - var animations = {}; + var frameId = 0; BETA.animate = function (callback) { + BETA.assert(frameId === 0, "There is already an animation running!"); + var prevTime; - var frameId; - var animId; frameId = requestAnimationFrame(function animationFn(time) { frameId = requestAnimationFrame(animationFn); - animations[animId] = frameId; var deltaTime = prevTime ? (time - prevTime) / 1000 @@ -614,20 +613,14 @@ prevTime = time; }); - - animId = frameId; - - animations[animId] = frameId; - - return animId; }; - BETA.stopAnimation = function (id) + BETA.stopAnimation = function () { - BETA.assert(animations[id], "There is no animation with ID " + id); + BETA.assert(frameId > 0, "There is no animation running!"); - cancelAnimationFrame(animations[id]); - delete animations[id]; + cancelAnimationFrame(frameId); + frameId = 0; }; //-------------INPUT HANDLING-------------\\