Is it possible to add more than one Sprite to an Container?
If i am running following code in my GameScene, only the Player “Layer” displays and everything works find (moving, cam follows PlayerContainer).
export default class PlayerContainer extends Phaser.GameObjects.Container {
constructor(scene, x, y, key, frame) {
super(scene, x, y);
this.debug = false;
this.scene = scene; // the scene this container will be added to
this.velocity = 160; // the velocity when moving our player
this.mapScale = this.scene.map.mapScale;
/*
Bewegung in alle Richtungen
Animationen enthalten aber nur 4 Himmelsrichtungen
*/
this.directions = [
"Up",
"Right",
"Down",
"Left",
"UpRight",
"DownRight",
"DownLeft",
"UpLeft",
];
this.lastDirection = this.directions[2];
this.moving = false;
this.idleTimer = 0;
this.playerRunPower = 100;
this.playerRun = false;
this.playerRunSwitch = false;
this.playerAttack = false;
this.playerAttackSwitch = false;
this.playerRunSpeed = 250;
this.createAnimations();
// enable physics
this.scene.physics.world.enable(this);
// scale our player Container
this.body.setSize(24, 32);
// this.setScale(1);
// collide with world bounds
this.body.setCollideWorldBounds(true);
// add the player to our existing scene
this.scene.add.existing(this);
// Kamera dem Spieler folgen
this.scene.cameras.main.startFollow(this);
//this.scene.cameras.main.setZoom(1.1);
this.depth = 3;
console.log(this.width, this.height, this.x, this.y);
this.player = new Player(this.scene, 12, 16, key, frame);
this.player.setScale(1.4);
this.player.setSize(24, 24);
// this.player.depth = 5;
this.playerShadow = new PlayerShadow(
this,
this.player.x * this.scale,
this.player.y * this.scale,
"hero_shadows",
0
);
// this.playerShadow.depth = 4;
this.add(this.player);
this.add(this.playerShadow);
}
Without this.playerShadow (commented out) everything works fine.
But if i try to add the shadow of the Player as an animated Sprite (Phaser.Physics.Arcade.Sprite) as the Player, i ran into this error.
“Uncaught TypeError: Cannot read property ‘queueDepthSort’ of undefined”
Anyone got the same behavior?