Skip to content

Instantly share code, notes, and snippets.

@vgheri
Created December 24, 2012 14:02
Show Gist options
  • Save vgheri/4369353 to your computer and use it in GitHub Desktop.
Save vgheri/4369353 to your computer and use it in GitHub Desktop.
Second part of the client update loop
// A single step of the client update loop (a frame)
function updateLoopStep() {
// Step 1: Clear canvas
pongR.canvasContext.clearRect(0, 0, pongR.settings.viewport.width, pongR.settings.viewport.height);
// Step 2: Handle user inputs (update internal model)
var playerInput = handleClientInputs(pongR.me);
if (playerInput !== null) {
// Step 3: Send the just processed input batch to the server.
sendInput(pongR.game.gameId, pongR.me.user.connectionId, playerInput);
}
if (!pongR.settings.naive_approach) {
interpolateClientMovements(pongR.other);
}
// Step 3: Draw the new frame in the canvas
drawScene();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment