Multiplayer tutorial 4: real-time game



Features on these Courses



40,816 visits, 170,689 views



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.

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.


  • Order by
Want to leave a comment? Login or Register an account!
  • Excuse me, i have question.

    On my project, peer alwasys follow host. what wrong? Mr Ashley

    Thank you


  • Please help me im trying to add a button ive tryed so many things but it will only show on one screen

  • You guys should ask on the forum not here.

  • I think there is something wrong with the code, perhaps, updates over the years messed it up. I have tested the game as host and peer, the host moves fine but peer's movement is somewhat restricted.

    EDIT: I realized it works fine when screens opened side by side however if you use "Remote Preview", than the peer does not move propoerly.

  • Not working anymore. Even the example seems to be broken

  • Load more comments (2 replies)