mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 21:21:41 +00:00
camera and input bugs
This commit is contained in:
parent
d7d2c7f67a
commit
d4e0a23838
4 changed files with 151 additions and 40 deletions
|
|
@ -118,7 +118,7 @@ class CameraController extends Object {
|
||||||
deltaposY = 0;
|
deltaposY = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var factor = isTouch ? Util.lerp(1 / 250, 1 / 10,
|
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;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
|
import src.JSPlatform;
|
||||||
|
import src.Util;
|
||||||
|
import gui.GuiControl.MouseState;
|
||||||
import h2d.TextInput;
|
import h2d.TextInput;
|
||||||
import h2d.Scene;
|
import h2d.Scene;
|
||||||
import hxd.res.BitmapFont;
|
import hxd.res.BitmapFont;
|
||||||
|
|
@ -50,4 +53,15 @@ class GuiTextInput extends GuiControl {
|
||||||
MarbleGame.canvas.scene2d.removeChild(text); // Refresh "layer"
|
MarbleGame.canvas.scene2d.removeChild(text); // Refresh "layer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override function onMousePress(mouseState:MouseState) {
|
||||||
|
super.onMousePress(mouseState);
|
||||||
|
|
||||||
|
#if js
|
||||||
|
if (Util.isTouchDevice()) {
|
||||||
|
text.text = js.Browser.window.prompt("Enter your name", text.text);
|
||||||
|
js.Browser.document.documentElement.requestFullscreen();
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package touch;
|
package touch;
|
||||||
|
|
||||||
|
import gui.GuiGraphics;
|
||||||
|
import h3d.Vector;
|
||||||
|
import gui.GuiControl;
|
||||||
import src.MarbleGame;
|
import src.MarbleGame;
|
||||||
import src.Settings;
|
import src.Settings;
|
||||||
import touch.TouchInput.TouchEventState;
|
import touch.TouchInput.TouchEventState;
|
||||||
|
|
@ -7,51 +10,141 @@ import touch.TouchInput.TouchEventState;
|
||||||
class CameraInput {
|
class CameraInput {
|
||||||
var identifier:Int = -1;
|
var identifier:Int = -1;
|
||||||
|
|
||||||
var doing = false;
|
|
||||||
|
|
||||||
public var enabled = false;
|
public var enabled = false;
|
||||||
|
|
||||||
public function new() {}
|
var added = false;
|
||||||
|
|
||||||
public function update(touchState:TouchEventState, joycam:Bool) {
|
var collider:GuiGraphics;
|
||||||
if (!enabled)
|
|
||||||
return;
|
public function new() {
|
||||||
if (!doing) {
|
var width = MarbleGame.canvas.scene2d.width;
|
||||||
// Check for touches on the right half of the screen
|
var height = MarbleGame.canvas.scene2d.height;
|
||||||
for (touch in touchState.changedTouches) {
|
|
||||||
if (touch.position.x >= Settings.optionsSettings.screenWidth / 2 && touch.state == Pressed) {
|
var g = new h2d.Graphics();
|
||||||
identifier = touch.identifier;
|
// g.beginFill(0xFF00FF, 0.5);
|
||||||
doing = true;
|
// g.drawRect(0, 0, width, height);
|
||||||
|
// g.endFill();
|
||||||
|
var gcollider = h2d.col.Bounds.fromValues(0, 0, width, height);
|
||||||
|
var interactive = new h2d.Interactive(width, height, g, gcollider);
|
||||||
|
|
||||||
|
this.collider = new GuiGraphics(g);
|
||||||
|
this.collider.position = new Vector(0, 0);
|
||||||
|
this.collider.extent = new Vector(width, height);
|
||||||
|
this.collider.horizSizing = Width;
|
||||||
|
this.collider.vertSizing = Height;
|
||||||
|
|
||||||
|
var pressed = false;
|
||||||
|
|
||||||
|
var prevMouse = new Vector(0, 0);
|
||||||
|
|
||||||
|
interactive.onPush = (e) -> {
|
||||||
|
e.propagate = true;
|
||||||
|
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (pressed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var scene2d = interactive.getScene();
|
||||||
|
if (e.relX < scene2d.width / 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pressed = true;
|
||||||
|
this.identifier = e.touchId;
|
||||||
|
prevMouse.x = e.relX;
|
||||||
|
prevMouse.y = e.relY;
|
||||||
|
}
|
||||||
|
|
||||||
|
interactive.onMove = (e) -> {
|
||||||
|
e.propagate = true;
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this.identifier != e.touchId)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (pressed) {
|
||||||
|
var curPos = new Vector(e.relX, e.relY);
|
||||||
|
var delta = curPos.sub(prevMouse);
|
||||||
|
var scaleFactor = 1.0;
|
||||||
|
#if js
|
||||||
|
scaleFactor = js.Browser.window.devicePixelRatio / Settings.zoomRatio;
|
||||||
|
#end
|
||||||
|
var jumpcam = MarbleGame.instance.touchInput.jumpButton.pressed || MarbleGame.instance.touchInput.powerupButton.pressed;
|
||||||
|
if (jumpcam) {
|
||||||
|
scaleFactor /= 2.5;
|
||||||
}
|
}
|
||||||
|
MarbleGame.instance.world.marble.camera.orbit(delta.x / scaleFactor, delta.y / scaleFactor, true);
|
||||||
|
prevMouse.x = e.relX;
|
||||||
|
prevMouse.y = e.relY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (doing) {
|
|
||||||
// Get our identifier
|
|
||||||
for (touch in touchState.changedTouches) {
|
|
||||||
if (touch.identifier == this.identifier) {
|
|
||||||
switch (touch.state) {
|
|
||||||
case Release:
|
|
||||||
doing = false;
|
|
||||||
return;
|
|
||||||
|
|
||||||
case Move:
|
interactive.onRelease = (e) -> {
|
||||||
var scaleFactor = 1.0;
|
e.propagate = true;
|
||||||
#if js
|
if (!enabled)
|
||||||
scaleFactor = js.Browser.window.devicePixelRatio / Settings.zoomRatio;
|
return;
|
||||||
#end
|
|
||||||
if (joycam) {
|
|
||||||
scaleFactor /= 2.5;
|
|
||||||
}
|
|
||||||
MarbleGame.instance.world.marble.camera.orbit(touch.deltaPosition.x / scaleFactor, touch.deltaPosition.y / scaleFactor, true);
|
|
||||||
return;
|
|
||||||
|
|
||||||
case _:
|
if (this.identifier != e.touchId)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
doing = false;
|
pressed = false;
|
||||||
|
this.identifier = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public function update(touchState:TouchEventState, joycam:Bool) {
|
||||||
|
// if (!enabled)
|
||||||
|
// return;
|
||||||
|
// if (!doing) {
|
||||||
|
// // Check for touches on the right half of the screen
|
||||||
|
// for (touch in touchState.changedTouches) {
|
||||||
|
// if (touch.position.x >= Settings.optionsSettings.screenWidth / 2 && touch.state == Pressed) {
|
||||||
|
// identifier = touch.identifier;
|
||||||
|
// doing = true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (doing) {
|
||||||
|
// // Get our identifier
|
||||||
|
// for (touch in touchState.changedTouches) {
|
||||||
|
// if (touch.identifier == this.identifier) {
|
||||||
|
// switch (touch.state) {
|
||||||
|
// case Release:
|
||||||
|
// doing = false;
|
||||||
|
// return;
|
||||||
|
// case Move:
|
||||||
|
// var scaleFactor = 1.0;
|
||||||
|
// #if js
|
||||||
|
// scaleFactor = js.Browser.window.devicePixelRatio / Settings.zoomRatio;
|
||||||
|
// #end
|
||||||
|
// if (joycam) {
|
||||||
|
// scaleFactor /= 2.5;
|
||||||
|
// }
|
||||||
|
// MarbleGame.instance.world.marble.camera.orbit(touch.deltaPosition.x / scaleFactor, touch.deltaPosition.y / scaleFactor, true);
|
||||||
|
// return;
|
||||||
|
// case _:
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// doing = false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function dispose() {
|
||||||
|
this.collider.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add(parentGui:GuiControl) {
|
||||||
|
parentGui.addChild(this.collider);
|
||||||
|
added = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function remove(parentGui:GuiControl) {
|
||||||
|
parentGui.removeChild(this.collider);
|
||||||
|
added = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,6 @@ class TouchInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update() {
|
public function update() {
|
||||||
this.cameraInput.update(currentTouchState, jumpButton.pressed || powerupButton.pressed);
|
|
||||||
previousTouchState = currentTouchState;
|
previousTouchState = currentTouchState;
|
||||||
currentTouchState = new TouchEventState();
|
currentTouchState = new TouchEventState();
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +106,8 @@ class TouchInput {
|
||||||
powerupButton.dispose();
|
powerupButton.dispose();
|
||||||
movementInput.dispose();
|
movementInput.dispose();
|
||||||
pauseButton.dispose();
|
pauseButton.dispose();
|
||||||
this.cameraInput.enabled = true;
|
cameraInput.dispose();
|
||||||
|
this.cameraInput = new CameraInput();
|
||||||
this.movementInput = new MovementInput();
|
this.movementInput = new MovementInput();
|
||||||
this.jumpButton = new JumpButton();
|
this.jumpButton = new JumpButton();
|
||||||
this.powerupButton = new PowerupButton();
|
this.powerupButton = new PowerupButton();
|
||||||
|
|
@ -116,6 +116,8 @@ class TouchInput {
|
||||||
jumpButton.add(parentGui);
|
jumpButton.add(parentGui);
|
||||||
powerupButton.add(parentGui);
|
powerupButton.add(parentGui);
|
||||||
movementInput.add(parentGui);
|
movementInput.add(parentGui);
|
||||||
|
cameraInput.add(parentGui);
|
||||||
|
cameraInput.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setControlsEnabled(enabled:Bool) {
|
public function setControlsEnabled(enabled:Bool) {
|
||||||
|
|
@ -123,6 +125,7 @@ class TouchInput {
|
||||||
this.powerupButton.setVisible(enabled);
|
this.powerupButton.setVisible(enabled);
|
||||||
this.movementInput.setVisible(enabled);
|
this.movementInput.setVisible(enabled);
|
||||||
this.pauseButton.setVisible(enabled);
|
this.pauseButton.setVisible(enabled);
|
||||||
|
this.cameraInput.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hideControls(parentGui:GuiControl) {
|
public function hideControls(parentGui:GuiControl) {
|
||||||
|
|
@ -130,10 +133,11 @@ class TouchInput {
|
||||||
powerupButton.remove(parentGui);
|
powerupButton.remove(parentGui);
|
||||||
movementInput.remove(parentGui);
|
movementInput.remove(parentGui);
|
||||||
pauseButton.remove(parentGui);
|
pauseButton.remove(parentGui);
|
||||||
|
cameraInput.remove(parentGui);
|
||||||
jumpButton.dispose();
|
jumpButton.dispose();
|
||||||
powerupButton.dispose();
|
powerupButton.dispose();
|
||||||
movementInput.dispose();
|
movementInput.dispose();
|
||||||
pauseButton.dispose();
|
pauseButton.dispose();
|
||||||
this.cameraInput.enabled = false;
|
cameraInput.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue