add dynamic joystick

This commit is contained in:
RandomityGuy 2024-06-30 00:00:56 +05:30
parent d10642c3d1
commit 9e7ab4f577
3 changed files with 20 additions and 0 deletions

View file

@ -86,6 +86,7 @@ typedef TouchSettings = {
var rewindButtonSize:Float;
var buttonJoystickMultiplier:Float;
var hideControls:Bool;
var dynamicJoystick:Bool;
var cameraSwipeExtent:Float;
}
@ -178,6 +179,7 @@ class Settings {
rewindButtonSize: 60,
buttonJoystickMultiplier: 2.5,
hideControls: false,
dynamicJoystick: false,
cameraSwipeExtent: 10.0
}
@ -409,6 +411,9 @@ class Settings {
if (touchSettings.cameraSwipeExtent == null) {
touchSettings.cameraSwipeExtent = 10.0;
}
if (touchSettings.dynamicJoystick == null) {
touchSettings.dynamicJoystick = false;
}
#end
if (touchSettings.cameraSwipeExtent == 0) {
touchSettings.cameraSwipeExtent = 10.0;
@ -531,6 +536,11 @@ class Settings {
Settings.optionsSettings.screenWidth / Settings.optionsSettings.screenHeight);
}
#if js
MarbleGame.canvas.onResize(MarbleGame.canvas.scene2d.width, MarbleGame.canvas.scene2d.height);
#end
// Console.log('Window resized to ${wnd.width} x ${wnd.height}, scene ${scene2d.width} x ${scene2d.height}');
MarbleGame.canvas.render(MarbleGame.canvas.scene2d);
});
}

View file

@ -51,6 +51,10 @@ 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);
}
return;
}

View file

@ -103,6 +103,12 @@ class MovementInput {
this.joystick.graphics.alpha = 1;
}
public function moveToFinger(e:hxd.Event) {
var size = Settings.touchSettings.joystickSize;
this.area.graphics.setPosition(e.relX - size * 3, e.relY - size * 3);
this.collider.onPush(e);
}
public function add(parentGui:GuiControl) {
parentGui.addChild(this.area);
added = true;