Created
December 24, 2012 14:02
-
-
Save vgheri/4369352 to your computer and use it in GitHub Desktop.
First part of the client update loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Starts the client update loop | |
function startUpdateLoop() { | |
if (pongR.goalTimestamp) { | |
var now = new Date().getTime(); | |
var timelapse = (now - pongR.goalTimestamp) / 1000; // in seconds | |
if (timelapse > pongR.settings.PAUSE_AFTER_GOAL) { // TODO Change here to adjust with network latency | |
pongR.goalTimestamp = undefined; | |
updateLoopStep(); | |
} | |
} | |
else { | |
updateLoopStep(); | |
} | |
// From MDN https://developer.mozilla.org/en-US/docs/DOM/window.requestAnimationFrame | |
// Your callback routine must itself call requestAnimationFrame() unless you want the animation to stop. | |
// We use requestAnimationFrame so that the the image is redrawn as many times as possible per second | |
startAnimation(startUpdateLoop, pongR.canvas); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment