Documentation for quick start client

This commit is contained in:
Jeremiah Billmann
2013-07-23 17:45:38 -04:00
parent f45cbb1119
commit f304375ff2
2 changed files with 36 additions and 5 deletions
+34 -3
View File
@@ -12,10 +12,41 @@ A simple, lightweight, HTML multiplayer game server (and client) for Node.js
## Quick Start
### Server
### Client
```js
// Initialize GarageServer.IO
GarageServerIO.initializeGarageServer('http://insertmygameurlhere.com', {
onReady: function () {
// Call your game loop
},
onUpdatePlayerPrediction: function (state, inputs, deltaTime) {
// If using client, process over inputs using current state and return new state
},
onInterpolation: function (previousState, targetState, amount) {
// If interpolating, return new state
},
onWorldState: function (state) {
// Extract world state sent from server
}
};
### Server
// Inside render loop, extract states
GarageServerIO.getStates(function (playerStates, entityStates) {
playerStates.forEach(function (player) {
ctxCanvas.fillRect(player.state.x, player.state.y, 5, 5);
});
entityStates.forEach(function (entity) {
ctxCanvas.fillRect(entity.state.x, entity.state.y, 5, 5);
});
});
// Inside physics loop, capture and send input
GarageServerIO.addInput(myInput);
```
## API
@@ -35,8 +66,8 @@ options = {
onEvent(callback(data)),
onWorldState(callback(state)),
onPing(callback(pingDelay)),
onUpdatePlayerPrediction(callback(state, inputs, deltaTime)),
onInterpolation(callback(previousState, targetState, amount)) : newState,
onUpdatePlayerPrediction(callback(state, inputs, deltaTime) : newState),
onInterpolation(callback(previousState, targetState, amount) : newState),
onReady(callback),
logging: true
}
+2 -2
View File
@@ -10,8 +10,8 @@ options = {
onEvent(callback(data)),
onWorldState(callback(state)),
onPing(callback(pingDelay)),
onUpdatePlayerPrediction(callback(state, inputs, deltaTime)),
onInterpolation(callback(previousState, targetState, amount)) : newState,
onUpdatePlayerPrediction(callback(state, inputs, deltaTime) : newState),
onInterpolation(callback(previousState, targetState, amount) : newState),
onReady(callback),
logging: true
}