Hey @patrykmaron,
For the "lobby" system, you can let players connect into your room handler, and only start the match when the client count reaches the number you specify. That's exactly what I'm doing on Crash Racing - the game only starts after having 4 players - or after a timeout of 10 seconds.
Example
onJoin (client, options: any) {
if (this.clients.length === 10) {
// change the state to notify clients the game has been started
this.state.started = true;
// additionally, you may lock the room to prevent new clients from joining it
this.lock()
}
}
For the "rounds", you can either use JavaScript's setTimeout()
, or the built-in this.clock.setTimeout()
, which returns an Delayed
instance, which you can pause/resume/clear later (http://colyseus.io/docs/api-room/#clock-clocktimer)
Slightly rewritten example:
onInit () {
// auto-start the state after 10 seconds
this.autoStartTimeout = this.clock.setTimeout(() => this.start(), 10 * 1000);
}
onJoin () {
if (this.clients.length === 10) {
this.autoStartTimeout.clear();
this.start();
}
}
start () {
// change the state to notify clients the game has been started
this.state.started = true;
// additionally, you may lock the room to prevent new clients from joining it
this.lock()
}
Note that this code wasn't tested, there might be some issue on it. Cheers!