Skip to content

Commit

Permalink
Merge pull request #14 from CookieShade/dev-branch
Browse files Browse the repository at this point in the history
Simplify animation system
  • Loading branch information
CookieShade authored Jul 25, 2016
2 parents 51ce68d + 64389a4 commit ab65ff1
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions BETA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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-------------\\
Expand Down

0 comments on commit ab65ff1

Please sign in to comment.