Hey, I don’t know if it’s just a copy/paste mistake but in your Player class it says:
create() {
addPlayer(id, x, y, direction) {
....
}
So first of all there is a missing closing } bracket after create() {. And the this.scene.physics.add is never called because it’s in addPlayer, not create. Maybe this helps already
I’m sorry, but I don’t think we (or at least I) can’t help you without seeing the real code then, because it’s not clear what (or how) you’re trying to achieve (this).
I think the original Player class (no extends ) was better.
Thanks… may I know why ?
I’m just trying everything … haha
In the scene you need to add a collider for it.
Turn on physics debug to confirm where the bodies are.
Yes, debug box is turn on …
I have 2 object this.player and I added this.player.currentPlayer
when I check this.player.x is always 0
when I check this.player.currentPlayer.x is the actual x position
If you need to swap out sprites or use a Player instance across multiple scenes, then you should use no parent class and put the sprite in currentPlayer. But you have to give only currentPlayer to Phaser’s methods because it can’t do anything with the Player instance itself. And you have to use the sprite’s coordinates in player.currentPlayer.x etc.
If you don’t need any of that, then Player can extend Arcade.Sprite instead. Make sure the super arguments match.
If the sprites are moving the debug display should show little velocity rays.
If you need to swap out sprites or use a Player instance across multiple scenes, then you should use no parent class and put the sprite in currentPlayer . But you have to give only currentPlayer to Phaser’s methods because it can’t do anything with the Player instance itself. And you have to use the sprite’s coordinates in player.currentPlayer.x etc.
When I put this.currentPlayer = this.player.currentPlayer , I get undefined as during this.player.create(), the addPlayer() was not completed yet
Should I be using a promise to for this.player.create() ??
Is there a way to return the Arcade.Sprite from the this.player.create() ??
Then I can just do :