Multiplayer tutorial 4: real-time game

Favourite 74 favourites
Tutorial written by AshleyOriginally published on 19th, March 2014 - 4 revisions

This tutorial assumes you have already read Multiplayer tutorial 1: concepts, Multiplayer tutorial 2: chat room and Multiplayer tutorial 3: pong.

The first tutorial covered the theory of how multiplayer games work and the way they need to be designed, using techniques like local input prediction and lag compensation. The second tutorial covered a practical example of a chat room, which dealt with practical use of signalling, connectivity and sending messages. The third covered the basics of syncing objects. This tutorial will now cover the final topics of designing real-time games, such as implementing the input prediction and lag compensation described in the first tutorial. This is an advanced subject; if you are not already comfortable with your knowledge, consider revising the prior tutorials. This tutorial also covers some of the same ground as the previous pong example again, which is worth revising.

To get going, open the Example: Multiplayer - real-time game example that comes with Construct 2. This can be found in the Select template or example dialog that opens when pressing File - New. As with the previous tutorial, the project will be described event-by-event in more detail than the comments already in the project.

Running and testing

As with the chat example, the real-time game example must also be run from the first layout (F4), since it needs a valid name entered from the Login layout.

When testing the tutorial multiplayer games, it's possible you will meet other people who happen to be running the tutorial at the same time. However users commonly go "away from keyboard" (AFK) and leave things running without attending to them, so don't be surprised if other people are present but don't respond to chat messages. If you don't happen to meet someone active, get a friend involved and do some testing with them!

It's also possible someone will already be hosting the tutorial but you won't be able to connect to them. If that happens, change either the game, instance or room name and you'll start a new game which you host yourself.

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.

Comments

5
Tedg 9,849 rep

Awesome tutorial and awesome tool :)

Wednesday, March 19, 2014 at 5:21:07 PM
0
Jayjay 19.0k rep

Thanks for this tutorial! :D

Wednesday, March 19, 2014 at 5:51:25 PM
3
superwifibattler 3,322 rep

How do you make this with a drag&drop game or a board game or something?

Wednesday, March 19, 2014 at 7:02:12 PM
6
exertia 2,625 rep

@ashley - is there a way to restrict # of players to say 2 or a predetermined number, and force additional players into a new room / game.

Wednesday, March 19, 2014 at 8:33:47 PM
1
SergioRM 6,879 rep

really interesting! thank you!

Wednesday, March 19, 2014 at 9:59:39 PM
1
rexrainbow 137.5k rep

Like @superwifibattler said, the prediction might not be useful in some cases like turned based game (board game, poker game) , could Ashley provide some hint about that?

Wednesday, March 19, 2014 at 11:15:51 PM
2
Joskin 6,089 rep

Thanks for this tutorial ! It's not easy !

@rexrainbow, what about using the messages system for cards game ?
I can try to make a simple example.

Thursday, March 20, 2014 at 9:06:27 AM
3
rexrainbow 137.5k rep

@Joskin

Yes, I know it's possible.
My idea is -
1. [peer] request a command
2. [peer] validate this command (could I run this command?)
3. [peer] if validated pass, execute this command and send this request to host

4. [host] receive command , then validate it
5. [host] if validated pass, execute this command and send this request to other peers
- if validated failed , something with that peer

6. [other peer] get validated command, execute it.

The validation function and execution function will be the same at host and peer. (peer and host will use the same function to validate command)

Thursday, March 20, 2014 at 9:34:26 AM
1
potpie1010 2,836 rep

Awesome tutorial; great feature.

There's no other game engine that's fun to use, yet is still able to produce actual games.

Multiplayer should be interesting!

Thursday, March 20, 2014 at 1:18:01 PM
1
bilgekaan 23.4k rep

Great feature and tutorial thank you!

Friday, March 21, 2014 at 11:48:30 PM
2
dynamiczny 438 rep

Is there any chance of obtaining the code for the signaling server? After all I would not like to infinitely rely on the server which I don't even have access to..

Could you provide the code so that we could set up our own signalling servers?

Tuesday, March 25, 2014 at 2:30:26 PM
1
qu0y 3,126 rep

Thank you Ashley!

Saturday, March 29, 2014 at 2:09:01 PM
1
drappdev 2,164 rep

I think i missed the section around the room size.
If i change the "Max Peers" value to 2, and then open 4 separate browser windows to the localhost:50000 address. the first 2 i login are entered into the room, whilst the 3rd & 4th are given the error "signalling error: room full".
If anyone knows how to push the extra players above the max peers into 'new' rooms. I would really appreciate the knowledge share.
Thanks

Tuesday, April 01, 2014 at 10:08:55 PM
1
AbelaNET 14.7k rep

Ashley, thanks. Great info.

Wednesday, April 02, 2014 at 8:20:19 AM
2
Wsoukkachang 1,433 rep

@drappdev The new auto-join feature should help you with your problem.

Thursday, April 10, 2014 at 3:26:15 AM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.