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,092 visits, 51,631 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

Introduction

Hello everyone,

in this tutorial i want to introduce you into using the Photonplugin for Construct 2 from ExitGames. We gonna create a whole working game (very simplified of course) which covers following points:

Basics

- Where to download and install Photonplugin

- Create a realtime app on the photon website that represents your server

- What's the difference between Scirras and ExitGames Multiplayer Plugin?

Local - Functions

- Create a debug log for a better overview

- Create a "CreatePlayer" function

- Create a "ResetRound" function

Multiplayer - Connecting, join and leave

- Preparation

- Add error catch

- Connecting to the lobby

- Connecting to a random room or create it if it doesn't exist

- Leaving a room by pressing 2 on the keyboard (for testcase)

Multiplayer - Handle player join and player leave event

- Preparation

- Create player objects on one authoritative player locally (Master Client)

- The Raise event explained

- Destroy player data and objects of the leaving player

Multiplayer - Handle object creation

- Send the Master Client data to all players to tell them where they can create their own local copies of all player objects

Mixed - Game relevant events combined with multiplayer

[L] = [LOCAL]

[M] = [MULTIPLAYER]

- [L] Set a position where to go and where to shoot and tell it to every other player

- [M] Handling the goto and shoot positions && Master Client starts the round

- [M] Start the round, "let them body movaaa"

- [L] Use rex_moveTo to determine that players arrived at their positions

- [M] Master Client tells everyone that players arrived and the fun begins!

- [L] Handle the impact of bullets on players

- [M] Master Client decides the real impact state and informs players

- [M] Players destroy the objects based on Master Clients decision

- [L] I want and end of all of this!

- [M] Okay guys, battle's over. For now...

Thank You

- The bitter end...

-> A capx file was added. Fully commented and ready to use. Remember to put you AppID in the Photon object.

Basics

Where to download and install Photonplugin

Visit the official photon website here.

On top hover on the blue realtime icon and click on SDK's.

On the next page select the drop down and choose Scirra. The photon plugin for Construct 2 will appear and you can click on download.

You will be prompted to create an account what you actually NEED to do. So just go ahead and create an account.

After downloading the photon plugin .zip file open it and extract the files photon.cs2addon and optional photon-chat.cs2addon. Open up Construct 2 and drag and drop those two files into Construct 2. A dialog appears asking you to confirm installation of the plugins. Allow that and you will be done!

Create a realtime app on the photon website that represents your server

After logging in go to your dashboard on top and click on realtime

Next step is to create a realtime app. Click on Create a new Realtime App. You simply need to enter a name and that's it. If not just fill out the rest as you wish. You should see something like this after:

What's the differences between Scirras and ExitGames Multiplayer Plugin?

Scirra's multiplayer plugin runs on a peer-to-peer base while photon is running a "dedicated" server handling all the events. The big advantage of the Photoncloud is that if a player disconnects the game is not stopping. In Scirras plugin one player becomes the server and if this server goes down everyone else will go down with it :) As a better explanation i made this simple graphic

  • 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! :)