From 3a52d292d7a66681e8971149f5f7dc686f056520 Mon Sep 17 00:00:00 2001 From: Matojeje Date: Sat, 18 Nov 2023 01:55:16 +0100 Subject: [PATCH] Fix turtle drag recentering --- src/components/Turtle.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/Turtle.ts b/src/components/Turtle.ts index 771d077..2037d95 100644 --- a/src/components/Turtle.ts +++ b/src/components/Turtle.ts @@ -77,13 +77,20 @@ export class Turtle extends Button { onDragStart(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) { this.isDragged = true; - this.dragOffset.set(dragX, dragY); + this.dragOffset.set(this.x, this.y); this.sprite.setTexture("turtle_jumping"); } onDrag(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) { super.onDrag(pointer, dragX, dragY); - this.setPosition(dragX + this.dragOffset.x, dragY + this.dragOffset.y); + const offsetDifference = new Phaser.Math.Vector2( + (this.originX - this.sprite.originX) * this.scaleX * this.sprite.width, + (this.originY - this.sprite.originY) * this.scaleY * this.sprite.height + ) + this.setPosition( + dragX + this.dragOffset.x + offsetDifference.x, + dragY + this.dragOffset.y + offsetDifference.y + ); } onDragEnd(