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...