Multiplayer tutorial 3: pong

Index

Features on these Courses

Stats

12,287 visits, 51,174 views

Tools

Game events

As with the chat example we have global constants for the game, instance and room name. These allow us to conveniently change the names on the signalling server without having to hunt through our events. However we also have a new global for the game state. The first player joining a room needs to wait until someone to play with also joins. Then the game will say "get ready", then "GO!". This global variable holds the current state.

Message log group

The previous chat example used a Text Box object set to textarea mode as the main chat and information log. However it's an opaque object so would obscure the layout if used in this example. Instead we use an ordinary Text object called LogText to show log messages. However normal Text objects don't support scrolling. To make sure messages keep being displayed even as they go off the bottom of the object, we implement our own scrolling system. This is done by using an array to store a line of text in each array index, and then deleting the first item to scroll it up a line. This is not specifically related to multiplayer games, but is a useful technique to cover anyway.

The AddLog function adds a new line by adding it to the end of the array ("push back"). If there are over 20 lines, it deletes the first line ("pop front") - so the first line will disappear from view. After that we completely reset the content of the LogText object: first it's cleared to empty, then we iterate the array and add each line in to the object in order. The end result is each time we call AddLog a new line is added to the end of the LogText object, and it scrolls up when it reaches 20 lines.

Now we can call AddLog in the Function object from anywhere else in the event sheet to conveniently add scrolled messages to LogText.

  • 0 Comments

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