From 69a1b5bc8a66952cb1732a4b527ff63a55542135 Mon Sep 17 00:00:00 2001 From: Golen Date: Sun, 19 Nov 2023 17:58:41 +0100 Subject: [PATCH] Fix turtle depth sorting --- src/components/Turtle.ts | 15 +++++++++++++-- src/scenes/OverworldState.ts | 8 ++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/Turtle.ts b/src/components/Turtle.ts index 9f30c07..6075869 100644 --- a/src/components/Turtle.ts +++ b/src/components/Turtle.ts @@ -65,7 +65,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); @@ -242,6 +242,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 */ @@ -346,7 +357,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');