Multiplayer tutorial 4: real-time game

26

Index

Contributors

Stats

50,555 visits, 195,920 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 19 Mar, 2014. Last updated 5 May, 2022

The rest of the Signalling group is more similar to the chat example; however there are still some more differences to come. First of all as before, once connected we log in with our username.

Then once logged in, we join the game room. As with the chat example, everyone who joins will end up in the same game. There's no limit here, and no need for auto-join as in the Pong example.

Once joined, we establish if we are the host. We do the same as the chat example: either the Host or Peer group is activated. However we also need to handle the Peer object already in the layout depending on whether we became host. If we're a peer, it's easy: we just destroy the object already in the layout. Sync object will automatically create, move and destroy any objects that are present on the host, including the object that represents our own player. However when we are the host, we adopt the existing Peer object in the layout as our own object that we control.

As with the pong example, the Peer object has a peerid instance variable to store the signalling-assigned peer ID. The Associate object with peer action is again also necessary to indicate to the multiplayer engine that this instance represents a player in the room. In this case we're adopting the object already in the layout, so we associate it with our own ID.

The remaining events in the Signalling group cover error handling in the same way as before.

  • 8 Comments

  • Order by
Want to leave a comment? Login or Register an account!