v1.4.0: the controller pointer can now pan the GameScene camera
This commit is contained in:
@@ -50,7 +50,8 @@ public class Camera extends Gizmo {
|
||||
int screenHeight;
|
||||
|
||||
public float[] matrix;
|
||||
|
||||
|
||||
public boolean scrollable = false;
|
||||
public PointF scroll;
|
||||
public PointF centerOffset;
|
||||
|
||||
|
||||
@@ -213,6 +213,7 @@ public class GameScene extends PixelScene {
|
||||
|
||||
super.create();
|
||||
Camera.main.zoom( GameMath.gate(minZoom, defaultZoom + SPDSettings.zoom(), maxZoom));
|
||||
Camera.main.scrollable = true;
|
||||
|
||||
scene = this;
|
||||
|
||||
|
||||
@@ -184,8 +184,29 @@ public class PixelScene extends Scene {
|
||||
PointF virtualCursorPos = ControllerHandler.getControllerPointerPos();
|
||||
virtualCursorPos.x += defaultZoom * sensitivity * Game.elapsed * xMove;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user