Full round-based multiplayer game with Photon

12

Index

Attached Files

The following files have been attached to this tutorial:

.capx

photontutorial.capx

Download now 184.34 KB

Stats

20,307 visits, 51,958 views

Tools

Translations

This tutorial hasn't been translated.

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 9 Feb, 2017. Last updated 19 Feb, 2019

Multiplayer - Connecting, join and leave

Preparation

Setup Photon

Before we can connect to anything we need to load the Photon object into our project. Create a new object scroll to the bottom and select Photon. Select the new Photon object in the list to see it's properties. In the properties you will find AppId. Go to the photonwebsite, login and under dashboard -> Realtime go ahead and click on the App ID: xxxxx... it should reveal itself and you can copy the whole id. Paste this id into the AppId field. Now switch the Region to the one close to you (right now i found a bug. Don't put "EU" instead put "eu". I had problems with connecting when doing it). Leave the rest as it is.

Setup Player, Bullet and Marker

Next we create our Player object, a bullet and a marker. To save time i put those images here that you can use. Import these images in Construct 2 but put the black and pink player into one object. So that frame 0 is black and frame 1 is pink. Remember to set the animation speed to 0 to not end up on the pink player frame.

Next we add some instance variables and behaviors to our two objects:

Player

Variables:

- id [Number]

- gotoX [Number]

- gotoY [Number]

- shootX [Number]

- shootY [Number]

Create a second image point and put it to position (64, 32). This is on the right side of the player. We gonna use this for later. Remember to aplly this point to ALL ANIMATIONS.

Behaviors:

rex MoveTo (Download here)

To install you need to place the folder rex_moveto in the .7z file into your Construct 2 install directory under ../Construct 2/exporters/html5/behaviors

On Window 10 for me it can be found here:

C:\Program Files\Construct 2\exporters\html5\behaviors

Bullet

Variables:

- id [Number]

Behaviors:

Bullet

DestroyOutsideLayout

Setup Arrays and Dictionaries

Now it's time to create some Arrays and Dictionaries that we are going to use for data transmissions between the players. Add a new subfolder in your object types called "Send". Next create an Array called "JoinDataArray" and give it a Width of 5 (Height: 1, Depth: 1). This array will hold the X and Y walk and shoot position information and a spawn status number for every player. After that create a Dictionary called "JoinDataDictionary". We will save the unique user id's called ActorNr in Photon together with these data.

Create another Array and another Dictionary called "WalkShootArray/Dictionary". Set the Width of the Array to 4 leave the rest at 1. This Array will hold the information of the X and Y positions where the players want to move and the X and Y positions where they want to shoot at.

Now add a "LocalWalkShootArray" with a width of 4 and at last an Array called "HitArray" with a width of 2.

Touch object

Because we want our game to be mobile ready too add a Touch object to your project.

Your Project should look like this now:

Continue on the next page...

  • 6 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • it won't let me chance gotoX/Y to Self.X/Y

  • First player connects to the room, but the second one doesnt

  • how to add ms(Ping or latency?

    for ex, (68ms)

  • (on data has sending will add 1 to enemy score and display it) When "collision" is, then the score is -2 then how will it be (on event 1)? I am trying too many times.so please help me...i am beginner

  • I know this is 2 years old already, but WOW!

    You are so amazing... thanks for helping me with this! Especially the part with sending a whole array to another player was really frustrating for me, I would never use Dictionaries to solve that problem, thanks for that awesome tutorial.

    I was struggling with the syncing of enemies in my game, finally got it now! :)