I’ve been trying every possibility now for days but nothing works.
What I want to do:
create a player with an Sprite and Physics. And I need to be able to change the Sprite later on during the game.
I made a class creating the Arcade Sprite like so:
export default class playerDefault extends Phaser.Physics.Arcade.Sprite {
constructor(scene, x, y) {
super(scene, x, y, "Texture")
scene.add.existing(this)
scene.physics.add.existing(this)
this.x = x;
this.y = y;
this.player = this.scene.player
this.playerAvatarPlaceholder = scene.playerAvatarPlaceholder
this.playerGroup = scene.playerGroup
console.log(this.playerGroup)
}
create() {
const player = this.scene.physics.add
.sprite(this.x, this.y, this.playerAvatarPlaceholder)
.setDepth(101)
.setVisible(true)
player.body.onOverlap = true
player.setName("playerCreated") //!not working in create
this.playerGroup.add(player) //!not working in create
console.log(this.playerGroup.getChildren())
}
preUpdate(time, delta) {
super.preUpdate(time, delta);
this.rotation += 0.01;
}
}
In my Scene I need to set the Depth which is already strange, but I can’t change the Texture!
this works:
this.player.setDepth(102) //needed
this.player.setName("localPlayer") //working
This does not work:
this.player.setTexture(this.playerAvatarPlaceholder2) //does not work
If I print out the DisplayList I do see the new Texture Key, but it not displaying!
If somebody know how to solve this, would be greatly appreciated…