From 899a86ba6f73d6f7cdae03b98cb766c5a69505cb Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sun, 30 Jun 2024 12:13:51 +0530 Subject: [PATCH] fix dyn joystick --- src/touch/CameraInput.hx | 12 +++++++++--- src/touch/MovementInput.hx | 23 ++++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/touch/CameraInput.hx b/src/touch/CameraInput.hx index 2c0407b0..5dd238cd 100644 --- a/src/touch/CameraInput.hx +++ b/src/touch/CameraInput.hx @@ -49,10 +49,16 @@ class CameraInput { var scene2d = interactive.getScene(); if (e.relX < scene2d.width / 2) { - if (Settings.touchSettings.dynamicJoystick) { - // Move that joystick over our finger - MarbleGame.instance.touchInput.movementInput.moveToFinger(e); + var restartG = @:privateAccess MarbleGame.instance.touchInput.pauseButton?.collider; + if (restartG != null) { + if (e.relY > restartG.getAbsPos().y + restartG.height) { + if (Settings.touchSettings.dynamicJoystick) { + // Move that joystick over our finger + MarbleGame.instance.touchInput.movementInput.moveToFinger(e); + } + } } + return; } diff --git a/src/touch/MovementInput.hx b/src/touch/MovementInput.hx index c7949840..797f6bed 100644 --- a/src/touch/MovementInput.hx +++ b/src/touch/MovementInput.hx @@ -7,6 +7,7 @@ import h2d.col.Bounds; import gui.GuiControl; import h3d.Vector; import gui.GuiGraphics; +import src.MarbleGame; class MovementInput { var area:GuiGraphics; @@ -109,11 +110,23 @@ class MovementInput { } public function moveToFinger(e:hxd.Event) { - var size = Settings.touchSettings.joystickSize; - var scene2d = collider.getScene(); - this.area.graphics.setPosition(Util.clamp(e.relX - size * 3, 0, scene2d.width / 2 - size * 6), - Util.clamp(e.relY - size * 3, 0, scene2d.height - size * 6)); - this.collider.onPush(e); + var restartG = @:privateAccess MarbleGame.instance.touchInput.pauseButton?.collider; + if (restartG != null) { + var size = Settings.touchSettings.joystickSize; + var scene2d = collider.getScene(); + this.area.graphics.setPosition(Util.clamp(e.relX - size * 3, 0, scene2d.width / 2 - size * 6), + Util.clamp(e.relY - size * 3, restartG.getAbsPos().y + restartG.height, scene2d.height - size * 6)); + + var xPos = Util.clamp(e.relX - this.area.graphics.x, size, size * 5); + var yPos = Util.clamp(e.relY - this.area.graphics.y, size, size * 5); + + this.value.x = (xPos - (size * 3)) / (size * 2); + this.value.y = (yPos - (size * 3)) / (size * 2); + + this.joystick.graphics.setPosition(this.area.graphics.x + xPos, this.area.graphics.y + yPos); + + this.collider.onPush(e); + } } public function add(parentGui:GuiControl) {