(NOTE: Before trying out the PhotonClient behavior as outlined here, you need to work through my demo as explained in my post of 2 Apr 1:17 am, top of page 11.)
As promised, here?s my Construct 2 PhotonClient behavior that you can now try adding to your own sprites:
https://dl.dropbox.com/u/54915877/photonclient.zip - install this in the usual way (sorry, I?ve not yet made it as an add-on).
Here are the ACEs you can use ? you?ll find examples of the use of each in my Workout demo (whose capx can be downloaded from https://dl.dropbox.com/u/54915877/photon.workout.capx) :
- On joined
- On leaving
- On web player/s to be created
- On web player joined
- On web player updated
- On web player leaving
- On collision with another player
- On impacted by another player
- On message
- On game server ready (currently unreliable ? needing the Photon team to add a connect event handler)
- Initialise data of web player to create (i.e. data to be used by C2 in creating web players)
- Set the web player's ID (this pairs the Photon-allocated photonID with the C2-allocated UID)
- WebPlayerX (The current X co-ordinate of the picked web player)
- WebPlayerY (The current Y co-ordinate of the picked web player)
- WebPlayerUID (The picked web player's UID)
- NumWebPlayersToMake (The number of web players to make)
- WebPlayerPID (The picked web player's Photon ID)
- Name (of either my player or the picked web player, as selected)
I?ve liberally commented my Workout demo, and I hope that?ll be sufficient documentation of the use of each of the ACEs.
The PhotonClient object also has these custom properties that can be set in the usual way, in (where else?) the Properties bar:
- Auto-repeat: If enabled, the arrow keys (and sprite movements) repeat if held down. Otherwise, keys need to be tapped repeatedly to produce movement. This can make it easier to control positioning.
- Tiled: If enabled, sprites move from tile to tile rather than pixel by pixel (see my comment below).
- Tile size: Length (in pixels) of tile side (default is 32).
- Random start: If enabled, my player starts in a randomly chosen vacant position (see my further comment below).
]] More about the ?Tiled? property: As with most multiplayer games, latency is a problem. It can result in jerky pixel-by-pixel movement. One simple way of dealing with it is to make big movements of sprites from tile to tile, rather than attempt smooth movements pixel by pixel. That?s why my Workout demo uses tile-by-tile movements.
]] More about the ?Random start? property: When enabled, a random initial position is chosen for your player and (most importantly) if there already happens to be a web player in that position, another position is chosen and checked, and so on, until a vacant position is found. Otherwise it?s up to you to choose the starting position, and to provide for the possibility of an initial collision.
Some things to note:
]] You need to use the ?Export project? (as a HTML5 website) option ? ?Preview will give you an error (try it!).
]] Don?t run the export through the minifier ? there?re still some kinks to be ironed out before it?ll meet the exacting requirements of the Google Closure Compiler.
]] The player name input, the ?Join? and ?Leave? buttons, and the header (?= Construct 2 <-> Photon Cloud multiplayer =?) are created before the C2 runtime kicks in. They can be styled in the photon_client-inputs.css file in the photon.workout/css folder, and the header can be changed by editing the inputs_header.txt file in the photon.workout folder.
]] The Photon Cloud allows for multiple rooms in a game lobby. At this stage, I?ve not attempted to implement that feature and my PhotonClient behavior accesses a single room (called ?C2demo?).