mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
android fixes
This commit is contained in:
parent
61140be919
commit
d970c87015
12 changed files with 58 additions and 33 deletions
|
|
@ -58,6 +58,9 @@ class CameraController extends Object {
|
||||||
public var CameraPitch:Float;
|
public var CameraPitch:Float;
|
||||||
public var CameraYaw:Float;
|
public var CameraYaw:Float;
|
||||||
|
|
||||||
|
public var nextCameraYaw:Float;
|
||||||
|
public var nextCameraPitch:Float;
|
||||||
|
|
||||||
public var phi:Float;
|
public var phi:Float;
|
||||||
public var theta:Float;
|
public var theta:Float;
|
||||||
|
|
||||||
|
|
@ -121,8 +124,11 @@ class CameraController extends Object {
|
||||||
var factor = isTouch ? Util.lerp(1 / 250, 1 / 25,
|
var factor = isTouch ? Util.lerp(1 / 250, 1 / 25,
|
||||||
Settings.controlsSettings.cameraSensitivity) : Util.lerp(1 / 2500, 1 / 100, Settings.controlsSettings.cameraSensitivity);
|
Settings.controlsSettings.cameraSensitivity) : Util.lerp(1 / 2500, 1 / 100, Settings.controlsSettings.cameraSensitivity);
|
||||||
|
|
||||||
CameraPitch += deltaposY * factor;
|
// CameraPitch += deltaposY * factor;
|
||||||
CameraYaw += deltaposX * factor;
|
// CameraYaw += deltaposX * factor;
|
||||||
|
|
||||||
|
nextCameraPitch = CameraPitch + deltaposY * factor;
|
||||||
|
nextCameraYaw = CameraYaw + deltaposX * factor;
|
||||||
|
|
||||||
// var rotX = deltaposX * 0.001 * Settings.controlsSettings.cameraSensitivity * Math.PI * 2;
|
// var rotX = deltaposX * 0.001 * Settings.controlsSettings.cameraSensitivity * Math.PI * 2;
|
||||||
// var rotY = deltaposY * 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);
|
// camera.position.add(cameraVerticalTranslation);
|
||||||
var camera = level.scene.camera;
|
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)) {
|
if (Key.isDown(Settings.controlsSettings.camForward)) {
|
||||||
CameraPitch += 0.75 * 5 * dt;
|
CameraPitch += 0.75 * 5 * dt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
src/Main.hx
10
src/Main.hx
|
|
@ -24,8 +24,6 @@ class Main extends hxd.App {
|
||||||
var debugProfiler:h3d.impl.Benchmark;
|
var debugProfiler:h3d.impl.Benchmark;
|
||||||
var loaded:Bool = false;
|
var loaded:Bool = false;
|
||||||
|
|
||||||
var keyCounter:Text;
|
|
||||||
|
|
||||||
override function init() {
|
override function init() {
|
||||||
super.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;
|
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);
|
s2d.scaleMode = Zoom(zoomRatio);
|
||||||
#end
|
#end
|
||||||
|
#if android
|
||||||
|
var zoomRatio = Window.getInstance().height / 600;
|
||||||
|
s2d.scaleMode = Zoom(zoomRatio);
|
||||||
|
#end
|
||||||
|
|
||||||
#if android
|
#if android
|
||||||
Window.getInstance().addEventTarget(ev -> {
|
Window.getInstance().addEventTarget(ev -> {
|
||||||
|
|
@ -62,9 +64,6 @@ class Main extends hxd.App {
|
||||||
marbleGame = new MarbleGame(s2d, s3d);
|
marbleGame = new MarbleGame(s2d, s3d);
|
||||||
MarbleGame.canvas.setContent(new MainMenuGui());
|
MarbleGame.canvas.setContent(new MainMenuGui());
|
||||||
|
|
||||||
keyCounter = new Text(DefaultFont.get(), s2d);
|
|
||||||
keyCounter.color = new Vector(1, 1, 1, 1);
|
|
||||||
|
|
||||||
loaded = true;
|
loaded = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -93,7 +92,6 @@ class Main extends hxd.App {
|
||||||
super.update(dt);
|
super.update(dt);
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
marbleGame.update(dt);
|
marbleGame.update(dt);
|
||||||
keyCounter.text = 'Mouse: ${Window.getInstance().mouseX} ${Window.getInstance().mouseY}';
|
|
||||||
// world.update(dt);
|
// world.update(dt);
|
||||||
// fpsCounter.text = 'FPS: ${this.engine.fps}';
|
// fpsCounter.text = 'FPS: ${this.engine.fps}';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,11 @@ typedef ControlsSettings = {
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TouchSettings = {
|
typedef TouchSettings = {
|
||||||
var joystickPos:Vector;
|
var joystickPos:Array<Float>;
|
||||||
var joystickSize:Float;
|
var joystickSize:Float;
|
||||||
var jumpButtonPos:Vector;
|
var jumpButtonPos:Array<Float>;
|
||||||
var jumpButtonSize:Float;
|
var jumpButtonSize:Float;
|
||||||
var powerupButtonPos:Vector;
|
var powerupButtonPos:Array<Float>;
|
||||||
var powerupButtonSize:Float;
|
var powerupButtonSize:Float;
|
||||||
var buttonJoystickMultiplier:Float;
|
var buttonJoystickMultiplier:Float;
|
||||||
}
|
}
|
||||||
|
|
@ -97,15 +97,15 @@ class Settings {
|
||||||
};
|
};
|
||||||
|
|
||||||
public static var touchSettings:TouchSettings = {
|
public static var touchSettings:TouchSettings = {
|
||||||
joystickPos: new Vector(100, 40),
|
joystickPos: [100, 40],
|
||||||
joystickSize: 50,
|
joystickSize: 50,
|
||||||
jumpButtonPos: new Vector(440, 320),
|
jumpButtonPos: [440, 320],
|
||||||
jumpButtonSize: 60,
|
jumpButtonSize: 60,
|
||||||
powerupButtonPos: new Vector(440, 180),
|
powerupButtonPos: [440, 180],
|
||||||
powerupButtonSize: 60,
|
powerupButtonSize: 60,
|
||||||
buttonJoystickMultiplier: 2.5
|
buttonJoystickMultiplier: 2.5
|
||||||
}
|
}
|
||||||
public static var progression = [0, 0, 0];
|
public static var progression = [24, 24, 52];
|
||||||
public static var highscoreName = "";
|
public static var highscoreName = "";
|
||||||
|
|
||||||
public static var uiScale = 1.0;
|
public static var uiScale = 1.0;
|
||||||
|
|
@ -206,8 +206,9 @@ class Settings {
|
||||||
if (optionsSettings.fov == 0 #if js || optionsSettings.fov == null #end)
|
if (optionsSettings.fov == 0 #if js || optionsSettings.fov == null #end)
|
||||||
optionsSettings.fov = 60;
|
optionsSettings.fov = 60;
|
||||||
controlsSettings = json.controls;
|
controlsSettings = json.controls;
|
||||||
if (json.touch != null)
|
if (json.touch != null) {
|
||||||
touchSettings = json.touch;
|
touchSettings = json.touch;
|
||||||
|
}
|
||||||
progression = json.progression;
|
progression = json.progression;
|
||||||
highscoreName = json.highscoreName;
|
highscoreName = json.highscoreName;
|
||||||
} else {
|
} 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;
|
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;
|
Settings.zoomRatio = zoomRatio;
|
||||||
#end
|
#end
|
||||||
|
#if android
|
||||||
|
var zoomRatio = Window.getInstance().height / 600;
|
||||||
|
Settings.zoomRatio = zoomRatio;
|
||||||
|
#end
|
||||||
#if hl
|
#if hl
|
||||||
Settings.optionsSettings.screenWidth = cast wnd.width / zoomRatio;
|
Settings.optionsSettings.screenWidth = cast wnd.width / zoomRatio;
|
||||||
Settings.optionsSettings.screenHeight = cast wnd.height / zoomRatio;
|
Settings.optionsSettings.screenHeight = cast wnd.height / zoomRatio;
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class Sky extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSkyboxCubeTextured(dmlPath:String) {
|
function createSkyboxCubeTextured(dmlPath:String) {
|
||||||
#if js
|
#if (js || android)
|
||||||
dmlPath = StringTools.replace(dmlPath, "data/", "");
|
dmlPath = StringTools.replace(dmlPath, "data/", "");
|
||||||
#end
|
#end
|
||||||
if (ResourceLoader.fileSystem.exists(dmlPath)) {
|
if (ResourceLoader.fileSystem.exists(dmlPath)) {
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,10 @@ import hxd.fs.FileSystem;
|
||||||
import haxe.io.Encoding;
|
import haxe.io.Encoding;
|
||||||
import haxe.io.Path;
|
import haxe.io.Path;
|
||||||
import haxe.io.Bytes;
|
import haxe.io.Bytes;
|
||||||
|
|
||||||
#if android
|
#if android
|
||||||
// import zygame.utils.hl.AssetsTools;
|
import zygame.utils.hl.AssetsTools;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
@:allow(fs.ManifestFileSystem)
|
@:allow(fs.ManifestFileSystem)
|
||||||
class ManifestEntry extends FileEntry {
|
class ManifestEntry extends FileEntry {
|
||||||
private var fs:ManifestFileSystem;
|
private var fs:ManifestFileSystem;
|
||||||
|
|
@ -80,7 +80,7 @@ class ManifestEntry extends FileEntry {
|
||||||
#if (sys && !android)
|
#if (sys && !android)
|
||||||
return sys.io.File.getBytes(file);
|
return sys.io.File.getBytes(file);
|
||||||
#elseif android
|
#elseif android
|
||||||
bytes = sys.io.File.getBytes(file); // AssetsTools.getBytes(file);
|
bytes = AssetsTools.getBytes(file);
|
||||||
return bytes;
|
return bytes;
|
||||||
#else
|
#else
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|
@ -211,7 +211,7 @@ class ManifestEntry extends FileEntry {
|
||||||
#if (sys && !android)
|
#if (sys && !android)
|
||||||
return sys.FileSystem.stat(file).size;
|
return sys.FileSystem.stat(file).size;
|
||||||
#elseif android
|
#elseif android
|
||||||
var fb = sys.io.File.getBytes(file); // AssetsTools.getBytes(file);
|
var fb = AssetsTools.getBytes(file);
|
||||||
return fb != null ? fb.length : 0;
|
return fb != null ? fb.length : 0;
|
||||||
#else
|
#else
|
||||||
return bytes != null ? bytes.length : 0;
|
return bytes != null ? bytes.length : 0;
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ class GuiControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
var scaleFactor = 1.0;
|
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;
|
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
|
#end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,11 @@ class TouchCtrlsEditGui extends GuiImage {
|
||||||
|
|
||||||
var joystick = new MovementInputEdit();
|
var joystick = new MovementInputEdit();
|
||||||
|
|
||||||
var jumpBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource, Settings.touchSettings.jumpButtonPos,
|
var jumpBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource,
|
||||||
Settings.touchSettings.jumpButtonSize);
|
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,
|
var powerupBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/energy.png").resource,
|
||||||
Settings.touchSettings.powerupButtonSize);
|
new Vector(Settings.touchSettings.powerupButtonPos[0], Settings.touchSettings.powerupButtonPos[1]), Settings.touchSettings.powerupButtonSize);
|
||||||
|
|
||||||
jumpBtn.onClick = (sender, mousePos) -> {
|
jumpBtn.onClick = (sender, mousePos) -> {
|
||||||
sender.setSelected(true);
|
sender.setSelected(true);
|
||||||
|
|
@ -62,7 +62,7 @@ class TouchCtrlsEditGui extends GuiImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
jumpBtn.onChangeCb = (sender, value, rvalue) -> {
|
jumpBtn.onChangeCb = (sender, value, rvalue) -> {
|
||||||
Settings.touchSettings.jumpButtonPos = value;
|
Settings.touchSettings.jumpButtonPos = [value.x, value.y];
|
||||||
Settings.touchSettings.jumpButtonSize = rvalue;
|
Settings.touchSettings.jumpButtonSize = rvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ class TouchCtrlsEditGui extends GuiImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
powerupBtn.onChangeCb = (sender, value, rvalue) -> {
|
powerupBtn.onChangeCb = (sender, value, rvalue) -> {
|
||||||
Settings.touchSettings.powerupButtonPos = value;
|
Settings.touchSettings.powerupButtonPos = [value.x, value.y];
|
||||||
Settings.touchSettings.powerupButtonSize = rvalue;
|
Settings.touchSettings.powerupButtonSize = rvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,7 +84,7 @@ class TouchCtrlsEditGui extends GuiImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
joystick.onChangeCb = (value, rvalue) -> {
|
joystick.onChangeCb = (value, rvalue) -> {
|
||||||
Settings.touchSettings.joystickPos = value;
|
Settings.touchSettings.joystickPos = [value.x, value.y];
|
||||||
Settings.touchSettings.joystickSize = rvalue;
|
Settings.touchSettings.joystickSize = rvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package touch;
|
package touch;
|
||||||
|
|
||||||
|
import hxd.res.DefaultFont;
|
||||||
|
import h2d.Text;
|
||||||
import gui.GuiGraphics;
|
import gui.GuiGraphics;
|
||||||
import h3d.Vector;
|
import h3d.Vector;
|
||||||
import gui.GuiControl;
|
import gui.GuiControl;
|
||||||
|
|
@ -16,6 +18,8 @@ class CameraInput {
|
||||||
|
|
||||||
var collider:GuiGraphics;
|
var collider:GuiGraphics;
|
||||||
|
|
||||||
|
var txt:Text;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
var width = MarbleGame.canvas.scene2d.width;
|
var width = MarbleGame.canvas.scene2d.width;
|
||||||
var height = MarbleGame.canvas.scene2d.height;
|
var height = MarbleGame.canvas.scene2d.height;
|
||||||
|
|
@ -37,6 +41,8 @@ class CameraInput {
|
||||||
|
|
||||||
var prevMouse = new Vector(0, 0);
|
var prevMouse = new Vector(0, 0);
|
||||||
|
|
||||||
|
txt = new Text(DefaultFont.get());
|
||||||
|
|
||||||
interactive.onPush = (e) -> {
|
interactive.onPush = (e) -> {
|
||||||
e.propagate = true;
|
e.propagate = true;
|
||||||
|
|
||||||
|
|
@ -66,6 +72,8 @@ class CameraInput {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
|
txt.text = 'Camera Touch: ${e.relX} ${e.relY}';
|
||||||
|
|
||||||
var curPos = new Vector(e.relX, e.relY);
|
var curPos = new Vector(e.relX, e.relY);
|
||||||
var delta = curPos.sub(prevMouse);
|
var delta = curPos.sub(prevMouse);
|
||||||
var scaleFactor = 1.0;
|
var scaleFactor = 1.0;
|
||||||
|
|
@ -140,6 +148,7 @@ class CameraInput {
|
||||||
|
|
||||||
public function add(parentGui:GuiControl) {
|
public function add(parentGui:GuiControl) {
|
||||||
parentGui.addChild(this.collider);
|
parentGui.addChild(this.collider);
|
||||||
|
MarbleGame.canvas.scene2d.addChild(txt);
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import src.Settings;
|
||||||
|
|
||||||
class JumpButton extends TouchButton {
|
class JumpButton extends TouchButton {
|
||||||
public function new() {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class MovementInput {
|
||||||
g.endFill();
|
g.endFill();
|
||||||
|
|
||||||
this.area = new GuiGraphics(g);
|
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.extent = new Vector(size * 6, size * 6);
|
||||||
this.area.vertSizing = Top;
|
this.area.vertSizing = Top;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class MovementInputEdit extends GuiGraphics {
|
||||||
|
|
||||||
super(g);
|
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.extent = new Vector(size * 6, size * 6);
|
||||||
this.vertSizing = Top;
|
this.vertSizing = Top;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ import src.Settings;
|
||||||
|
|
||||||
class PowerupButton extends TouchButton {
|
class PowerupButton extends TouchButton {
|
||||||
public function new() {
|
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);
|
this.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue