Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions src/Event/AnimationLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ CAAT.Module({
CAAT.ENDRAF=false;

/**
* if setInterval, this value holds CAAT.setInterval return value.
* This value holds setInterval ID or RAF handler ID required to stop the CAAT loop
* @type {null}
*/
CAAT.INTERVAL_ID=null;
CAAT.LOOP_ID=null;

/**
* Boolean flag to determine if CAAT.loop has already been called.
Expand Down Expand Up @@ -110,11 +110,14 @@ CAAT.Module({
*/
CAAT.endLoop=function () {
if (CAAT.NO_RAF) {
if (CAAT.INTERVAL_ID !== null) {
clearInterval(CAAT.INTERVAL_ID);
if (CAAT.LOOP_ID !== null) {
clearInterval(CAAT.LOOP_ID);
}
} else {
CAAT.ENDRAF = true;
if (CAAT.LOOP_ID !== null) {
window.cancelRequestAnimFrame(CAAT.LOOP_ID);
}
}

CAAT.renderEnabled = false;
Expand All @@ -139,7 +142,7 @@ CAAT.Module({
CAAT.FPS = fps || 60;
CAAT.renderEnabled = true;
if (CAAT.NO_RAF) {
CAAT.INTERVAL_ID = setInterval(
CAAT.LOOP_ID = setInterval(
function () {
var t = new Date().getTime();

Expand All @@ -163,6 +166,7 @@ CAAT.Module({
1000 / CAAT.FPS
);
} else {
CAAT.ENDRAF = false;
CAAT.renderFrameRAF();
}
};
Expand All @@ -186,7 +190,7 @@ CAAT.Module({
c.FRAME_TIME = new Date().getTime() - t;


window.requestAnimFrame(c.renderFrameRAF, 0);
CAAT.LOOP_ID = window.requestAnimFrame(c.renderFrameRAF, 0);
};

/**
Expand All @@ -199,9 +203,23 @@ CAAT.Module({
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function raf(/* function */ callback, /* DOMElement */ element) {
window.setTimeout(callback, 1000 / CAAT.FPS);
return window.setTimeout(callback, 1000 / CAAT.FPS);
};
})();

/**
* Polyfill for cancelRequestAnimationFrame.
*/
window.cancelRequestAnimFrame = (function () {
return window.cancelRequestAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFramee ||
window.oCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame ||
function cancelRaf(handleID) {
window.clearTimeout(handleID);
};
})();
})();
},

extendsWith:function () {
Expand Down