Multiplayer tutorial 3: pong

18

Index

Stats

31,306 visits, 109,717 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 22 Apr, 2014. Last updated 11 Jan, 2022

Login layout

This layout is virtually identical to the previous chat room tutorial login layout. It simply serves to allow the user to enter a username in to a text box. The username is stored in a global variable and used to log in to the signalling server on the next layout.

Game layout

The Game layout now has an object for the host's paddle on the left, and the ball. When a peer joins, their paddle will be created on the right. Both players always see the host on the left and the peer (the second player to join) on the right.

The ChatLog textarea has been replaced with an ordinary Text object, so objects can be seen beneath it. An array is used to simulate scrolling up the messages, which will be described in more detail shortly.

The events for this layout deal with the same signalling events the previous chat example did. However on top of that it also deals with synchronising the paddles and the ball in real-time. For simplicity this example does not include a chat, so player's only inputs are their paddle positions, controlled by mouse. Also for simplicity, there is no lag compensation. If there is high latency, the peer on the right may miss the ball even if they see themselves hit it, because only the host tests for a collision and they see the peer on a long delay. Since lag compensation can be a little tricky, we won't deal with it in this tutorial - the fourth tutorial (real-time game) covers that. The game should still work fine over low-latency connections such as LANs.

This is a relatively complex example, with a total of 40 events. We'll begin looking at these events on the next page.

Next Tutorial In Course

Multiplayer tutorial 4: real-time game 25:38

Learn the advanced concepts of real-time multiplayer games, including input prediction and lag compensation.

  • 4 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Re: "Sync object will automatically create and destroy objects, but when they are created we need to set their peerid instance variable so we can later know which peer the object represents."

    => Why don't we use the Sync instance variable action in order to complete the Paddle object synchronization with its peerid instance variable value?

  • does this tutorial still work? if i am a host i don't see the peer movement

  • как сделать систему очков?хочу чтобы счет у двоих показывало