mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-05 17:30:44 +08:00
Completed: Client Side Prediction
This commit is contained in:
@@ -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'),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user