Skip to content

Instantly share code, notes, and snippets.

@vgheri
Created December 24, 2012 14:02
Show Gist options
  • Save vgheri/4369352 to your computer and use it in GitHub Desktop.
Save vgheri/4369352 to your computer and use it in GitHub Desktop.
First part of the client update loop
// 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