Added onReady callback

This commit is contained in:
Jeremiah Billmann
2013-07-18 22:51:02 -04:00
parent b5449342cd
commit 0453f140d3
2 changed files with 38 additions and 30 deletions
+5
View File
@@ -12,6 +12,7 @@ options = {
onPing: function (pingDelay),
onUpdatePlayerPhysics: function (state, inputs, deltaTime),
onInterpolation: function(previousState, targetState, amount)
onReady: function (),
logging: true
}
api methods
@@ -199,6 +200,10 @@ var GarageServerIO = (function (socketio) {
_stateController.smoothingFactor = data.smoothingFactor;
_stateController.worldState = data.worldState;
if(_options.onReady) {
_options.onReady();
}
setInterval(function (){
_socket.emit('ping', new Date().getTime());
}, _stateController.pingInterval);
+33 -30
View File
@@ -7,6 +7,7 @@ $(function () {
GarageServerIO.initializeGarageServer('http://garageserver_io.jbillmann.c9.io', {
logging: true,
onReady: startGame,
onUpdatePlayerPhysics: GamePhysics.getNewPlayerState,
onInterpolation: GamePhysics.getInterpolatedState,
onWorldState: function (state) {
@@ -17,37 +18,39 @@ $(function () {
}
});
GameLoop.start(
//Render Loop
function () {
ctxCanvas.clearRect(0, 0, canvas.width, canvas.height);
GarageServerIO.getStates(function (playerStates, entityStates) {
playerStates.forEach(function (player) {
ctxCanvas.fillRect(player.state.x, player.state.y, playerSize, playerSize);
});
function startGame() {
GameLoop.start(
//Render Loop
function () {
ctxCanvas.clearRect(0, 0, canvas.width, canvas.height);
GarageServerIO.getStates(function (playerStates, entityStates) {
playerStates.forEach(function (player) {
ctxCanvas.fillRect(player.state.x, player.state.y, playerSize, playerSize);
});
entityStates.forEach(function (entity) {
ctxCanvas.fillRect(entity.state.x, entity.state.y, entitySize, entitySize);
entityStates.forEach(function (entity) {
ctxCanvas.fillRect(entity.state.x, entity.state.y, entitySize, entitySize);
});
});
});
},
//Update Loop
function () {
if (keyboard.pressed('left')) {
GarageServerIO.addInput('left');
},
//Update Loop
function () {
if (keyboard.pressed('left')) {
GarageServerIO.addInput('left');
}
if (keyboard.pressed('right')) {
GarageServerIO.addInput('right');
}
if (keyboard.pressed('down')) {
GarageServerIO.addInput('down');
}
if (keyboard.pressed('up')) {
GarageServerIO.addInput('up');
}
if (keyboard.pressed('space')) {
GarageServerIO.addInput('space');
}
}
if (keyboard.pressed('right')) {
GarageServerIO.addInput('right');
}
if (keyboard.pressed('down')) {
GarageServerIO.addInput('down');
}
if (keyboard.pressed('up')) {
GarageServerIO.addInput('up');
}
if (keyboard.pressed('space')) {
GarageServerIO.addInput('space');
}
}
);
);
}
});