Skip to content

Commit

Permalink
Fix turtle drag recentering
Browse files Browse the repository at this point in the history
  • Loading branch information
Matojeje committed Nov 18, 2023
1 parent 2c028d0 commit 3a52d29
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/Turtle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3a52d29

Please sign in to comment.