v1.4.0: the controller pointer can now pan the GameScene camera

This commit is contained in:
Evan Debenham
2022-09-13 13:26:40 -04:00
parent 7279e6f33b
commit 39fa4adbe1
3 changed files with 26 additions and 3 deletions

View File

@@ -50,7 +50,8 @@ public class Camera extends Gizmo {
int screenHeight; int screenHeight;
public float[] matrix; public float[] matrix;
public boolean scrollable = false;
public PointF scroll; public PointF scroll;
public PointF centerOffset; public PointF centerOffset;

View File

@@ -213,6 +213,7 @@ public class GameScene extends PixelScene {
super.create(); super.create();
Camera.main.zoom( GameMath.gate(minZoom, defaultZoom + SPDSettings.zoom(), maxZoom)); Camera.main.zoom( GameMath.gate(minZoom, defaultZoom + SPDSettings.zoom(), maxZoom));
Camera.main.scrollable = true;
scene = this; scene = this;

View File

@@ -184,8 +184,29 @@ public class PixelScene extends Scene {
PointF virtualCursorPos = ControllerHandler.getControllerPointerPos(); PointF virtualCursorPos = ControllerHandler.getControllerPointerPos();
virtualCursorPos.x += defaultZoom * sensitivity * Game.elapsed * xMove; virtualCursorPos.x += defaultZoom * sensitivity * Game.elapsed * xMove;
virtualCursorPos.y += defaultZoom * sensitivity * Game.elapsed * yMove; virtualCursorPos.y += defaultZoom * sensitivity * Game.elapsed * yMove;
virtualCursorPos.x = GameMath.gate(0, virtualCursorPos.x, Game.width);
virtualCursorPos.y = GameMath.gate(0, virtualCursorPos.y, Game.height); PointF cameraShift = new PointF();
if (virtualCursorPos.x < 0){
cameraShift.x = virtualCursorPos.x;
virtualCursorPos.x = 0;
} else if (virtualCursorPos.x > Camera.main.screenWidth()){
cameraShift.x = (virtualCursorPos.x - Camera.main.screenWidth());
virtualCursorPos.x = Camera.main.screenWidth();
}
if (virtualCursorPos.y < 0){
cameraShift.y = virtualCursorPos.y;
virtualCursorPos.y = 0;
} else if (virtualCursorPos.y > Camera.main.screenHeight()){
cameraShift.y = (virtualCursorPos.y - Camera.main.screenHeight());
virtualCursorPos.y = Camera.main.screenHeight();
}
cameraShift.invScale(Camera.main.zoom);
if (cameraShift.length() > 0 && Camera.main.scrollable){
Camera.main.shift(cameraShift);
}
ControllerHandler.updateControllerPointer(virtualCursorPos, true); ControllerHandler.updateControllerPointer(virtualCursorPos, true);
} }
} }