android fixes

This commit is contained in:
RandomityGuy 2022-08-12 14:55:16 +05:30
parent 61140be919
commit d970c87015
12 changed files with 58 additions and 33 deletions

View file

@ -58,6 +58,9 @@ class CameraController extends Object {
public var CameraPitch:Float;
public var CameraYaw:Float;
public var nextCameraYaw:Float;
public var nextCameraPitch:Float;
public var phi:Float;
public var theta:Float;
@ -121,8 +124,11 @@ class CameraController extends Object {
var factor = isTouch ? Util.lerp(1 / 250, 1 / 25,
Settings.controlsSettings.cameraSensitivity) : Util.lerp(1 / 2500, 1 / 100, Settings.controlsSettings.cameraSensitivity);
CameraPitch += deltaposY * factor;
CameraYaw += deltaposX * factor;
// CameraPitch += deltaposY * factor;
// CameraYaw += deltaposX * factor;
nextCameraPitch = CameraPitch + deltaposY * factor;
nextCameraYaw = CameraYaw + deltaposX * factor;
// var rotX = deltaposX * 0.001 * Settings.controlsSettings.cameraSensitivity * Math.PI * 2;
// var rotY = deltaposY * 0.001 * Settings.controlsSettings.cameraSensitivity * Math.PI * 2;
@ -147,6 +153,11 @@ class CameraController extends Object {
// camera.position.add(cameraVerticalTranslation);
var camera = level.scene.camera;
var lerpt = hxd.Math.min(1, 1 - Math.pow(0.6, dt * 600));
CameraYaw = Util.lerp(CameraYaw, nextCameraYaw, lerpt);
CameraPitch = Util.lerp(CameraPitch, nextCameraPitch, lerpt);
if (Key.isDown(Settings.controlsSettings.camForward)) {
CameraPitch += 0.75 * 5 * dt;
}

View file

@ -24,8 +24,6 @@ class Main extends hxd.App {
var debugProfiler:h3d.impl.Benchmark;
var loaded:Bool = false;
var keyCounter:Text;
override function init() {
super.init();
@ -36,6 +34,10 @@ class Main extends hxd.App {
var zoomRatio = Util.isTouchDevice() ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 600 : js.Browser.window.devicePixelRatio; // js.Browser.window.devicePixelRatio;
s2d.scaleMode = Zoom(zoomRatio);
#end
#if android
var zoomRatio = Window.getInstance().height / 600;
s2d.scaleMode = Zoom(zoomRatio);
#end
#if android
Window.getInstance().addEventTarget(ev -> {
@ -62,9 +64,6 @@ class Main extends hxd.App {
marbleGame = new MarbleGame(s2d, s3d);
MarbleGame.canvas.setContent(new MainMenuGui());
keyCounter = new Text(DefaultFont.get(), s2d);
keyCounter.color = new Vector(1, 1, 1, 1);
loaded = true;
});
@ -93,7 +92,6 @@ class Main extends hxd.App {
super.update(dt);
if (loaded) {
marbleGame.update(dt);
keyCounter.text = 'Mouse: ${Window.getInstance().mouseX} ${Window.getInstance().mouseY}';
// world.update(dt);
// fpsCounter.text = 'FPS: ${this.engine.fps}';
}

View file

@ -51,11 +51,11 @@ typedef ControlsSettings = {
}
typedef TouchSettings = {
var joystickPos:Vector;
var joystickPos:Array<Float>;
var joystickSize:Float;
var jumpButtonPos:Vector;
var jumpButtonPos:Array<Float>;
var jumpButtonSize:Float;
var powerupButtonPos:Vector;
var powerupButtonPos:Array<Float>;
var powerupButtonSize:Float;
var buttonJoystickMultiplier:Float;
}
@ -97,15 +97,15 @@ class Settings {
};
public static var touchSettings:TouchSettings = {
joystickPos: new Vector(100, 40),
joystickPos: [100, 40],
joystickSize: 50,
jumpButtonPos: new Vector(440, 320),
jumpButtonPos: [440, 320],
jumpButtonSize: 60,
powerupButtonPos: new Vector(440, 180),
powerupButtonPos: [440, 180],
powerupButtonSize: 60,
buttonJoystickMultiplier: 2.5
}
public static var progression = [0, 0, 0];
public static var progression = [24, 24, 52];
public static var highscoreName = "";
public static var uiScale = 1.0;
@ -206,8 +206,9 @@ class Settings {
if (optionsSettings.fov == 0 #if js || optionsSettings.fov == null #end)
optionsSettings.fov = 60;
controlsSettings = json.controls;
if (json.touch != null)
if (json.touch != null) {
touchSettings = json.touch;
}
progression = json.progression;
highscoreName = json.highscoreName;
} else {
@ -235,6 +236,10 @@ class Settings {
var zoomRatio = Util.isTouchDevice() ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 600 : js.Browser.window.devicePixelRatio; // 768 / js.Browser.window.innerHeight; // js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio / 768;
Settings.zoomRatio = zoomRatio;
#end
#if android
var zoomRatio = Window.getInstance().height / 600;
Settings.zoomRatio = zoomRatio;
#end
#if hl
Settings.optionsSettings.screenWidth = cast wnd.width / zoomRatio;
Settings.optionsSettings.screenHeight = cast wnd.height / zoomRatio;

View file

@ -60,7 +60,7 @@ class Sky extends Object {
}
function createSkyboxCubeTextured(dmlPath:String) {
#if js
#if (js || android)
dmlPath = StringTools.replace(dmlPath, "data/", "");
#end
if (ResourceLoader.fileSystem.exists(dmlPath)) {

View file

@ -27,10 +27,10 @@ import hxd.fs.FileSystem;
import haxe.io.Encoding;
import haxe.io.Path;
import haxe.io.Bytes;
#if android
// import zygame.utils.hl.AssetsTools;
import zygame.utils.hl.AssetsTools;
#end
@:allow(fs.ManifestFileSystem)
class ManifestEntry extends FileEntry {
private var fs:ManifestFileSystem;
@ -80,7 +80,7 @@ class ManifestEntry extends FileEntry {
#if (sys && !android)
return sys.io.File.getBytes(file);
#elseif android
bytes = sys.io.File.getBytes(file); // AssetsTools.getBytes(file);
bytes = AssetsTools.getBytes(file);
return bytes;
#else
return bytes;
@ -211,7 +211,7 @@ class ManifestEntry extends FileEntry {
#if (sys && !android)
return sys.FileSystem.stat(file).size;
#elseif android
var fb = sys.io.File.getBytes(file); // AssetsTools.getBytes(file);
var fb = AssetsTools.getBytes(file);
return fb != null ? fb.length : 0;
#else
return bytes != null ? bytes.length : 0;

View file

@ -120,7 +120,7 @@ class GuiControl {
}
var scaleFactor = 1.0;
#if js
#if (js || android)
scaleFactor = 1 / Settings.zoomRatio; // 768 / js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio; // 0.5; // 768 / js.Browser.window.innerHeight; // js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio / 768;
#end

View file

@ -49,11 +49,11 @@ class TouchCtrlsEditGui extends GuiImage {
var joystick = new MovementInputEdit();
var jumpBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource, Settings.touchSettings.jumpButtonPos,
Settings.touchSettings.jumpButtonSize);
var jumpBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource,
new Vector(Settings.touchSettings.jumpButtonPos[0], Settings.touchSettings.jumpButtonPos[1]), Settings.touchSettings.jumpButtonSize);
var powerupBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/energy.png").resource, Settings.touchSettings.powerupButtonPos,
Settings.touchSettings.powerupButtonSize);
var powerupBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/energy.png").resource,
new Vector(Settings.touchSettings.powerupButtonPos[0], Settings.touchSettings.powerupButtonPos[1]), Settings.touchSettings.powerupButtonSize);
jumpBtn.onClick = (sender, mousePos) -> {
sender.setSelected(true);
@ -62,7 +62,7 @@ class TouchCtrlsEditGui extends GuiImage {
}
jumpBtn.onChangeCb = (sender, value, rvalue) -> {
Settings.touchSettings.jumpButtonPos = value;
Settings.touchSettings.jumpButtonPos = [value.x, value.y];
Settings.touchSettings.jumpButtonSize = rvalue;
}
@ -73,7 +73,7 @@ class TouchCtrlsEditGui extends GuiImage {
}
powerupBtn.onChangeCb = (sender, value, rvalue) -> {
Settings.touchSettings.powerupButtonPos = value;
Settings.touchSettings.powerupButtonPos = [value.x, value.y];
Settings.touchSettings.powerupButtonSize = rvalue;
}
@ -84,7 +84,7 @@ class TouchCtrlsEditGui extends GuiImage {
}
joystick.onChangeCb = (value, rvalue) -> {
Settings.touchSettings.joystickPos = value;
Settings.touchSettings.joystickPos = [value.x, value.y];
Settings.touchSettings.joystickSize = rvalue;
}

View file

@ -1,5 +1,7 @@
package touch;
import hxd.res.DefaultFont;
import h2d.Text;
import gui.GuiGraphics;
import h3d.Vector;
import gui.GuiControl;
@ -16,6 +18,8 @@ class CameraInput {
var collider:GuiGraphics;
var txt:Text;
public function new() {
var width = MarbleGame.canvas.scene2d.width;
var height = MarbleGame.canvas.scene2d.height;
@ -37,6 +41,8 @@ class CameraInput {
var prevMouse = new Vector(0, 0);
txt = new Text(DefaultFont.get());
interactive.onPush = (e) -> {
e.propagate = true;
@ -66,6 +72,8 @@ class CameraInput {
return;
if (pressed) {
txt.text = 'Camera Touch: ${e.relX} ${e.relY}';
var curPos = new Vector(e.relX, e.relY);
var delta = curPos.sub(prevMouse);
var scaleFactor = 1.0;
@ -140,6 +148,7 @@ class CameraInput {
public function add(parentGui:GuiControl) {
parentGui.addChild(this.collider);
MarbleGame.canvas.scene2d.addChild(txt);
added = true;
}

View file

@ -8,6 +8,7 @@ import src.Settings;
class JumpButton extends TouchButton {
public function new() {
super(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource, Settings.touchSettings.jumpButtonPos, Settings.touchSettings.jumpButtonSize);
super(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource,
new Vector(Settings.touchSettings.jumpButtonPos[0], Settings.touchSettings.jumpButtonPos[1]), Settings.touchSettings.jumpButtonSize);
}
}

View file

@ -32,7 +32,7 @@ class MovementInput {
g.endFill();
this.area = new GuiGraphics(g);
this.area.position = Settings.touchSettings.joystickPos;
this.area.position = new Vector(Settings.touchSettings.joystickPos[0], Settings.touchSettings.joystickPos[1]);
this.area.extent = new Vector(size * 6, size * 6);
this.area.vertSizing = Top;

View file

@ -31,7 +31,7 @@ class MovementInputEdit extends GuiGraphics {
super(g);
this.position = Settings.touchSettings.joystickPos;
this.position = new Vector(Settings.touchSettings.joystickPos[0], Settings.touchSettings.joystickPos[1]);
this.extent = new Vector(size * 6, size * 6);
this.vertSizing = Top;

View file

@ -8,7 +8,8 @@ import src.Settings;
class PowerupButton extends TouchButton {
public function new() {
super(ResourceLoader.getImage("data/ui/touch/energy.png").resource, Settings.touchSettings.powerupButtonPos, Settings.touchSettings.powerupButtonSize);
super(ResourceLoader.getImage("data/ui/touch/energy.png").resource,
new Vector(Settings.touchSettings.powerupButtonPos[0], Settings.touchSettings.powerupButtonPos[1]), Settings.touchSettings.powerupButtonSize);
this.setEnabled(false);
}
}