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 rewindButtonSize:Float;
var buttonJoystickMultiplier:Float; var buttonJoystickMultiplier:Float;
var hideControls:Bool; var hideControls:Bool;
var dynamicJoystick:Bool;
var cameraSwipeExtent:Float; var cameraSwipeExtent:Float;
} }
@ -178,6 +179,7 @@ class Settings {
rewindButtonSize: 60, rewindButtonSize: 60,
buttonJoystickMultiplier: 2.5, buttonJoystickMultiplier: 2.5,
hideControls: false, hideControls: false,
dynamicJoystick: false,
cameraSwipeExtent: 10.0 cameraSwipeExtent: 10.0
} }
@ -409,6 +411,9 @@ class Settings {
if (touchSettings.cameraSwipeExtent == null) { if (touchSettings.cameraSwipeExtent == null) {
touchSettings.cameraSwipeExtent = 10.0; touchSettings.cameraSwipeExtent = 10.0;
} }
if (touchSettings.dynamicJoystick == null) {
touchSettings.dynamicJoystick = false;
}
#end #end
if (touchSettings.cameraSwipeExtent == 0) { if (touchSettings.cameraSwipeExtent == 0) {
touchSettings.cameraSwipeExtent = 10.0; touchSettings.cameraSwipeExtent = 10.0;
@ -531,6 +536,11 @@ class Settings {
Settings.optionsSettings.screenWidth / Settings.optionsSettings.screenHeight); 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); MarbleGame.canvas.render(MarbleGame.canvas.scene2d);
}); });
} }

View file

@ -51,6 +51,10 @@ class CameraInput {
var scene2d = interactive.getScene(); var scene2d = interactive.getScene();
if (e.relX < scene2d.width / 2) { if (e.relX < scene2d.width / 2) {
if (Settings.touchSettings.dynamicJoystick) {
// Move that joystick over our finger
MarbleGame.instance.touchInput.movementInput.moveToFinger(e);
}
return; return;
} }

View file

@ -103,6 +103,12 @@ class MovementInput {
this.joystick.graphics.alpha = 1; 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) { public function add(parentGui:GuiControl) {
parentGui.addChild(this.area); parentGui.addChild(this.area);
added = true; added = true;