mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-08-11 11:12:33 +08:00
Documentation for quick start client
This commit is contained in:
@@ -12,10 +12,41 @@ A simple, lightweight, HTML multiplayer game server (and client) for Node.js
|
|||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
|
### Server
|
||||||
|
|
||||||
### Client
|
### 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
|
## API
|
||||||
|
|
||||||
@@ -35,8 +66,8 @@ options = {
|
|||||||
onEvent(callback(data)),
|
onEvent(callback(data)),
|
||||||
onWorldState(callback(state)),
|
onWorldState(callback(state)),
|
||||||
onPing(callback(pingDelay)),
|
onPing(callback(pingDelay)),
|
||||||
onUpdatePlayerPrediction(callback(state, inputs, deltaTime)),
|
onUpdatePlayerPrediction(callback(state, inputs, deltaTime) : newState),
|
||||||
onInterpolation(callback(previousState, targetState, amount)) : newState,
|
onInterpolation(callback(previousState, targetState, amount) : newState),
|
||||||
onReady(callback),
|
onReady(callback),
|
||||||
logging: true
|
logging: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ options = {
|
|||||||
onEvent(callback(data)),
|
onEvent(callback(data)),
|
||||||
onWorldState(callback(state)),
|
onWorldState(callback(state)),
|
||||||
onPing(callback(pingDelay)),
|
onPing(callback(pingDelay)),
|
||||||
onUpdatePlayerPrediction(callback(state, inputs, deltaTime)),
|
onUpdatePlayerPrediction(callback(state, inputs, deltaTime) : newState),
|
||||||
onInterpolation(callback(previousState, targetState, amount)) : newState,
|
onInterpolation(callback(previousState, targetState, amount) : newState),
|
||||||
onReady(callback),
|
onReady(callback),
|
||||||
logging: true
|
logging: true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user