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,315 visits, 51,967 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

Local - Functions

Create a debug log for a better overview

Before we start going into multiplayer i recommend to create a debug log where you can show all kinds of messages to keep an overview of what happens in your game.

To do this create a new project add a TextBox object place it in your layout and set it's type to Textarea.

Create a Function object, go to your Event sheet and add a new event. Pick the Function object from the list and add a On function event. Name it "Debug". Now create a new action inside of it. Pick the TextBox object and add it's Set text action. Into the textline enter the following: trim(Self.Text & newline & Function.Param(0)). That adds new text below the existing one in the textbox. Finally add a Scroll to bottom action. Your event should look like this.

Create a "CreatePlayer" function

We create a general function to create a player object according to the programming law "don't repeat yourself". For this add a new On function event and call it "CreatePlayer". This function receives 5 values. The gotoX, gotoY, shootX and shootY positions and the Players unique id (ActorNr). First we add the Systems Create Object action, add the Player and set as X-Position Function.Param(0) which simply grabs the first value in the parameter list given to this function. For Y use Function.Param(1). Next set player objects instance variable values. We wanna set the shootX and shootY values. Those can be found in the Parameter list at position 2 and 3. Go ahead and set these values now. Now we want to set our id for the player object. This is also an instance variable so do the same as before but use position 4 from the Parameter list.

When the player object is created we can simply set our gotoX and gotoY to the actual position of the object by using Self.X and Self.Y. Finally to differ our local player from the others we want to colorize our player to pink. Our player object consists of two different frames. First = black color, Second = pink color. Depending on if the given unique id in the parameter equals our local id we set the color to pink otherwise to black. For this we use this expression: Player.id = Photon.MyActorNr ? 1 : 0

Create a "ResetRound" function

This function is really simple. We simply reset our global variables here, clear the WalkShootDictionary and remove all marker objects to allow the player to set new positions again.

Done! We are ready to start through and get right into creating the next gen mmor.. wait. Let's keep it simple for now ;)

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