How to build a Multiplayer Game with Photon

Favourite 23 favourites
Tutorial written by SirvoidOriginally published on 25th, March 2016 - 13 revisions

This simple tutorial will teach you how to create a simple platformer game & a simple chat with Photon in only 12 events.

The plugin is available here : https://www.scirra.com/forum/plugin-photon-cloud_t125222

Photon Setup

First of all you need a Photon Real time cloud service on PhotonEngine.com
Make a account and take the free plan for this tutorial.

After that copy the App ID who is there on your page :


And Prepare your Construct 2.

Make a blank project and insert the Photon Plugin.
After that past your App-ID here:
This is all for the Setup of the Photon Plugin.

Connexion

Do a thing like:
On start of the layout connect to the server and when the player is connected to the server make it join a room or create a room automatically Like this :


Create Player on each screen

The tutorial really start here. :p
This is the time to say to the game than when someone join the room the game will create a character for the player.

First create a sprite with a variable named ActorNr.
And now we will use the raise event for the first time.


*
The code is the number of the event.

Data is if you want to send something with the event.

the Cache save the event for later when someone will join the game the event will be automatically reexecuted for this player at the start of the layout.

Receiver is who will received the event.
*

The other thing are not important for this tutorial.

And finally we associate the Photon Player ID and the character of the player to be able to select them later.

Finally all of this will be a thing like this:


Send your Position to every player


I made a small mistake here , replace each int by float


The movement behaviour are enabled only for the player object who have your ID.
And your X & Y are send to other players.

Add this line to destroy the sprite of the players who left the game


Simple Chat

For the chat add these objects:
TextBox named chatlog : To show what the people say.
Textbox named msgbox : To write what you want to say.
Button named sendbutton: To send your message.

And do this simple thing:


Conclusion

This is all you need to know to make a multiplayer platformer game & a chat with Photon.
If something don't work the capx is attached to this tutorial.
:D

Unlock your full gamedev potential

Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!

View deals

Plus, it's got a lot of additional features that will help you save time and make more impressive games!

Congratulations on finishing this tutorial!

Did you learn a lot from it? Share it now with your friends!

Share and Copy this Tutorial

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

Comments

0
daimonfrey12 356 rep

i cant download capx A potentially dangerous Request.Path value was detected from the client (&).

Saturday, March 26, 2016 at 4:53:21 PM
0
Sirvoid 7,194 rep
i cant download capx A potentially dangerous Request.Path value was detected from the client (&).
quoted from daimonfrey12

oh my bad the capx didn't work for X reason.

Saturday, March 26, 2016 at 5:50:34 PM
0
Reflextions 12.9k rep

For some reason the other player float a few pixels of the ground for whoever the player is not playing with. Is there a way to fix this?

Tuesday, May 31, 2016 at 5:52:54 PM
0
zizman 354 rep

What is the best way to do Turnbased game?

Friday, August 12, 2016 at 6:47:24 PM
0
donotsecret 821 rep

Could somebody upload working .capx this lesson. I for some reason it is impossible to repeat.

Sunday, October 23, 2016 at 4:43:39 PM
-1
Sirvoid 7,194 rep
Could somebody upload working .capx this lesson. I for some reason it is impossible to repeat.
quoted from donotsecret

The capx is already attached to this tutorial.

Monday, November 14, 2016 at 1:39:04 PM
0
MrRiker30 1,394 rep

Hello, is the capx / plugin working on the R239 version ? Because nothing works :( When I lauch the game, it's the same as the layout : I got a chat window :D

Saturday, December 10, 2016 at 12:16:41 AM
1
MrRiker30 1,394 rep

Found the issue. By default, the "region" propertie in the Photon object is set to "EU". Click on the arrow to expand and choose your region, even if it's eu too. It must be in lowercases.

Saturday, December 10, 2016 at 12:30:42 AM
0
RayKi 2,522 rep

Ok... so I can check if there is any room to join and if there isn't I can create one. But how do I check if a specific room exists?

Tuesday, January 17, 2017 at 5:25:15 PM
0
Vodakman 495 rep

Great tutorial, but how do I make a sprite only appear for a specific player? Haven't seen anything in the photon plugin specific to this.

Friday, February 10, 2017 at 1:11:30 PM
0
yme 2,379 rep

Thanks. I was able to make this work. Did not try the capx file, just made it from scratch myself. Then only thing is that, I was not able to make the chatlog change line with newline. All text stayed on the same line. Oh well, maybe just my n00byness.

Monday, March 27, 2017 at 7:02:43 PM
0
Christmas 2,163 rep

Really cool tutorial. I was wondering if I added a login screen and stored the name to a variable, would there was be a way to assign that unique name to each player that will appear in the chat-box rather than the numbers <1> <2> etc? Can't figure it out.

Thursday, May 11, 2017 at 5:13:30 PM
1
Christmas 2,163 rep

Figured the naming issue out...
Set name of local actor to ACTORNAMEVARIABLE

Then alter the On Event 4 line to...
Chatlog - Set text to chatlog.Text & newline & PhotonTest.ActorNameByNR(PhotonTest.ActorNR) & ": " & PhotonTest.EventData

I am not a number I am a free man

Thursday, May 18, 2017 at 1:51:51 PM
0
joshua112200 1,137 rep

I managed to solve my error here I created a boolean to know if the player is alive then my game was top but you could talk like I can do other players to see the animations because it is only the player walking stopped and it becomes ugly it

Sunday, October 15, 2017 at 7:21:44 PM
0
joshua112200 1,137 rep

I managed to solve my error here I created a boolean to know if the player is alive then my game was top but you could talk like I can do other players to see the animations because it is only the player walking stopped and it becomes ugly it

Sunday, October 15, 2017 at 7:51:56 PM

Leave a comment

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