Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When logging in, later players may not be able to see who is around them. #47

Open
shoshoi opened this issue Aug 22, 2022 · 5 comments
Open

Comments

@shoshoi
Copy link

shoshoi commented Aug 22, 2022

Hello, thanks for this useful software !

When logging in, later players may not be able to see who is around them. Still, the call can be made.
Sometimes this happens, sometimes it does not.
I am trying this on the same host, with the same browser, and multiple tabs open.

@shoshoi
Copy link
Author

shoshoi commented Aug 22, 2022

The earlier report was in error.
When logging in, players who arrive later may not be able to see who is around and cannot make calls.
Seems to happen when the server is under low load.

@gusdnvkfks
Copy link

Yeah my problem is like that too.

But I tried sevral times and the characters, hided, appeared suddenly.

I mean I have no idea what the problem is.

plz let me know if you have any idea the software working right way...

@hawkcookie
Copy link

hawkcookie commented Nov 9, 2022

@gusdnvkfks @shoshoi
Yes. I have the same problem. Well.., The reason may be the registration timing of phaserEvents. Especially, phaserEvents.emit(Event.PLAYER_JOINED) is often called before phaserEvents.on(Event.PLAYER_JOINED) under a given server conditions.
From now i have no idea for solution. As reference, phaser and colyseus tutorial page is in https://learn.colyseus.io/phaser/
In this tutorial, phaser#create block method calls joinOrCreate and defines onAdd callback. It may solve our problem.

import { Client, Room } from "colyseus.js";

// custom scene class
export class GameScene extends Phaser.Scene {
    // (...)

    client = new Client("ws://localhost:2567");
    room: Room;

    async create() {
      console.log("Joining room...");

      try {
        this.room = await client.joinOrCreate("my_room");
        console.log("Joined successfully!");

      } catch (e) {
        console.error(e);
      }
    }

    // (...)
}
export class GameScene extends Phaser.Scene {
    // (...)
    room: Room;

    // we will assign each player visual representation here
    // by their `sessionId`
    playerEntities: {[sessionId: string]: any} = {};

    // (...)
    async create() {
        // (...)

        // listen for new players
        this.room.state.players.onAdd((player, sessionId) => {
            const entity = this.physics.add.image(player.x, player.y, 'ship_0001');

            // keep a reference of it on `playerEntities`
            this.playerEntities[sessionId] = entity;
        });

        // (...)
    }
}

@vinkent420
Copy link

Yeah my problem is like that too with still latest version of Colyseus (0.15)

@kevinshen56714 , do you have any ideas for fixing this one? Thank and so appreciate!

@droncaglio
Copy link

droncaglio commented Jul 21, 2024

As @hawkcookie described, if the server is responding to fast, the phaserEvents.emit(Event.PLAYER_JOINED) happens before our player register phaserEvents.on(Event.PLAYER_JOINED). What I did to fix is not elegant, but it works. If someone with more experience on web development can suggest a way to await the event. I fixed by delaying the "emit" like this:

Network.ts

initialize(){

// bunch of code



// track changes on every child object inside the players MapSchema
      player.onChange = (changes) => {
        changes.forEach((change) => {
          const { field, value } = change
          phaserEvents.emit(Event.PLAYER_UPDATED, field, value, key)

          // when a new player finished setting up player name
          if (field === 'name' && value !== '') {
            console.log('Network emit Player Joined:', value)

            // delay 0.5 second 
            setTimeout(() => {
              phaserEvents.emit(Event.PLAYER_JOINED, player, key)
              store.dispatch(setPlayerNameMap({ id: key, name: value }))
              store.dispatch(pushPlayerJoinedMessage(value))
            }
              , 500)

          }
        })
      }

// bunch of code
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants