diff --git a/src/components/Turtle.ts b/src/components/Turtle.ts index ce9eb47..b88901a 100644 --- a/src/components/Turtle.ts +++ b/src/components/Turtle.ts @@ -69,7 +69,7 @@ export class Turtle extends Button { this.spriteSize = 200; this.sprite = this.scene.add.sprite(0, 0, "turtle_waiting"); this.sprite.setScale(this.spriteSize / this.sprite.width); - this.add(this.sprite); + // this.add(this.sprite); /* Controls */ this.physicsPosition = new Phaser.Math.Vector2(x, y); @@ -250,6 +250,17 @@ export class Turtle extends Button { this.sprite.setTexture("turtle_jumping"); } } + + // Depth sorting + this.sprite.setPosition(this.x, this.y); + let depth = 100; + if (this.isOnTrampoline) { + depth += this.jumpTarget.y / 100; + } else { + depth += this.walkTarget.y / 100; + } + if (this.hold) depth += 100; + this.sprite.setDepth(depth); } /* Jumping */ @@ -354,7 +365,7 @@ export class Turtle extends Button { this.lostBalance = false; this.hasCrashed = false; this.bounceCount = 0; - this.onDrag(pointer, 0, 0); + this.onDrag(pointer, this.x, this.y); } onDrag(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) { diff --git a/src/scenes/OverworldState.ts b/src/scenes/OverworldState.ts index 85e54fb..927a3ea 100644 --- a/src/scenes/OverworldState.ts +++ b/src/scenes/OverworldState.ts @@ -77,6 +77,14 @@ export class OverworldState extends Phaser.GameObjects.Container { }); } + setVisible(value: boolean): this { + this.turtles.forEach((turtle) => { + turtle.sprite.setVisible(value); + }); + + return super.setVisible(value); + } + addDust(x: number, y: number) { let xpl = this.scene.add.sprite(x, y, 'dust_explosion');