Completed: Client Side Prediction

This commit is contained in:
Jeremiah Billmann
2013-06-12 22:29:38 -04:00
parent 649fece9f0
commit cd95410f00
3 changed files with 65 additions and 12 deletions
+23 -1
View File
@@ -1,5 +1,27 @@
$(function () {
GarageServerIO.connectToGarageServer('http://garageserver_io.jbillmann.c9.io', { logging: true });
GarageServerIO.connectToGarageServer('http://garageserver_io.jbillmann.c9.io', {
logging: true,
clientSidePrediction: true,
onUpdatePhysics: function (state, inputs) {
var i = 0;
if (!state.x && !state.y) {
state.x = 0;
state.y = 0;
}
for (i = 0; i < inputs.length; i ++) {
if (inputs[i].input === 'left') {
state.x -= 1;
} else if (inputs[i].input === 'right') {
state.x += 1;
} else if (inputs[i].input === 'down') {
state.y += 1;
} else if (inputs[i].input === 'up') {
state.y -= 1;
}
}
return state;
}
});
var gameCanvas = document.getElementById('gameCanvas'),