From 23f38fed0a54598e086ed6411020d90c7612c2e5 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Fri, 26 Jul 2013 21:38:07 -0400 Subject: [PATCH] Progress: Documentation --- README.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 56ae320..a43826b 100644 --- a/README.md +++ b/README.md @@ -63,13 +63,26 @@ GarageServerIO.initializeGarageServer('http://insertmygameurlhere.com', { // Call your game loop }, onUpdatePlayerPrediction: function (state, inputs, deltaTime) { - // If using client prediction, process over inputs using current state and deltaTime and return new state + var newState = {}; + if (!player.state.x) { + player.state.x = 0; + } + for (i = 0; i < player.inputs.length; i ++) { + if (player.inputs[i].input === 'left') { + newState.x -= (50 * deltaTime); + } else if (inputs[i].input === 'right') { + newState.x += (50 * deltaTime); + } + } }, onInterpolation: function (previousState, targetState, amount) { - // If interpolating, return new state using the previous state, target state, and the amount of progress towards the latter + var interpolationState = {}; + interpolationState.x = (previousState.x + amount * (targetState.x - previousState.x)); + return interpolationState; }, onWorldState: function (state) { - // Extract world state sent from server + document.getElementById('gameCanvas').style.width = state.width; + document.getElementById('gameCanvas').style.height = state.height; } }; ```