fix dyn joystick

This commit is contained in:
RandomityGuy 2024-06-30 12:13:51 +05:30
parent 7fe505c6a8
commit 899a86ba6f
2 changed files with 27 additions and 8 deletions

View file

@ -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;
}

View file

@ -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) {