You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This tutorial still uses version 0.15. We're gradually migrating content to version 0.16.
9
-
</Callout>
10
-
11
7
# 1: Basic Player Movement
12
8
13
9
This guide will show you how you can build a multiplayer experience with Colyseus Multiplayer Framework and Phaser.
@@ -333,6 +329,14 @@ For this demo, we only need one sprite to represent the player, which we are goi
333
329
334
330
After a connection with the room has been established, the client-side can start listening for state changes, and create a visual representation of the data in the server.
335
331
332
+
In order to attach callbacks to the state, we need to import the `getStateCallbacks()` function from `colyseus.js`:
333
+
334
+
```typescript
335
+
import { getStateCallbacks } from"colyseus.js";
336
+
// (...)
337
+
const $ =getStateCallbacks(this.room);
338
+
```
339
+
336
340
### Adding new players
337
341
338
342
As per [Room State and Schema](#room-state-and-schema) section, whenever the server accepts a new connection - the `onJoin()` method is creating a new Player instance within the state.
@@ -341,7 +345,7 @@ We're going to listen to this event on the client-side now:
@@ -355,6 +359,8 @@ When playing the Scene, you should see a message in the console of the browser w
355
359
For the visual representation, we need to add a Phaser GameObject for each joining player, and keep a local reference to the GameObject based on their `sessionId`, so we can operate on them later:
356
360
357
361
```ts
362
+
import { getStateCallbacks } from"colyseus.js";
363
+
358
364
exportclassGameSceneextendsPhaser.Scene {
359
365
// (...)
360
366
room:Room;
@@ -368,7 +374,7 @@ export class GameScene extends Phaser.Scene {
This tutorial still uses version 0.15. We're gradually migrating content to version 0.16.
9
-
</Callout>
10
-
11
7
# 3: Client Predicted Input
12
8
13
9
This guide will show you how you can build a multiplayer experience with Colyseus Multiplayer Framework and Phaser.
@@ -57,7 +53,7 @@ export class GameScene extends Phaser.Scene {
57
53
Now, let's modify the `players.onAdd()` callback to identify which player is the current one, by checking the `sessionId` key against the connected `room.sessionId`:
0 commit comments