Multiplayer tutorial 2: chat room

Index

Taggé

Statistiques

1,642 visites, 2,026 vues

Partager

Outils

Login layout

The first layout Login does not need much explanation. It is essentially just a text box with a Join button. The entered name is stored in a global variable and no connection actually happens until the next layout.

The events for the layout simply deal with focusing the text box, ensuring you can't join before typing in a name, and storing the entered name in the MyUsername global variable when joining. Also it checks the Is supported condition in the Multiplayer object - not all browsers support WebRTC yet, and we should inform the user if it won't work for them.

Chat layout

The Chat layout connects in On start of layout, using the name stored in the MyUsername global variable.

The objects in the layout are designed to mimic a common chat room app: the main ChatLog is where chat messages appear, the PeerList on the right lists the names of the other people in the chat room, and there is a text box with a Send button along the bottom to send messages with. (You can also press return to send a message.)

The events for this layout will deal with:

- connecting to the signalling server and logging in

- joining the chat room

- listing who else is in the room and updating the list as people join and leave

- displaying received chat messages

- sending any chat messages entered locally

- dealing with any errors or disconnections that occur

We'll begin looking at the actual events on the next page of the tutorial.

  • 0 Comments

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