v1.4.0: the controller pointer can now pan the GameScene camera
This commit is contained in:
@@ -51,6 +51,7 @@ public class Camera extends Gizmo {
|
|||||||
|
|
||||||
public float[] matrix;
|
public float[] matrix;
|
||||||
|
|
||||||
|
public boolean scrollable = false;
|
||||||
public PointF scroll;
|
public PointF scroll;
|
||||||
public PointF centerOffset;
|
public PointF centerOffset;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user