v1.2.0: added camera offset functionality
This commit is contained in:
@@ -52,6 +52,7 @@ public class Camera extends Gizmo {
|
|||||||
public float[] matrix;
|
public float[] matrix;
|
||||||
|
|
||||||
public PointF scroll;
|
public PointF scroll;
|
||||||
|
public PointF centerOffset;
|
||||||
|
|
||||||
private float shakeMagX = 10f;
|
private float shakeMagX = 10f;
|
||||||
private float shakeMagY = 10f;
|
private float shakeMagY = 10f;
|
||||||
@@ -122,6 +123,7 @@ public class Camera extends Gizmo {
|
|||||||
screenHeight = (int)(height * zoom);
|
screenHeight = (int)(height * zoom);
|
||||||
|
|
||||||
scroll = new PointF();
|
scroll = new PointF();
|
||||||
|
centerOffset = new PointF();
|
||||||
|
|
||||||
matrix = new float[16];
|
matrix = new float[16];
|
||||||
Matrix.setIdentity( matrix );
|
Matrix.setIdentity( matrix );
|
||||||
@@ -140,11 +142,14 @@ public class Camera extends Gizmo {
|
|||||||
|
|
||||||
public void zoom( float value, float fx, float fy ) {
|
public void zoom( float value, float fx, float fy ) {
|
||||||
|
|
||||||
|
PointF offsetAdjust = centerOffset.clone();
|
||||||
|
centerOffset.scale(zoom).invScale(value);
|
||||||
|
|
||||||
zoom = value;
|
zoom = value;
|
||||||
width = (int)(screenWidth / zoom);
|
width = (int)(screenWidth / zoom);
|
||||||
height = (int)(screenHeight / zoom);
|
height = (int)(screenHeight / zoom);
|
||||||
|
|
||||||
snapTo( fx, fy );
|
snapTo( fx - offsetAdjust.x, fy - offsetAdjust.y );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resize( int width, int height ) {
|
public void resize( int width, int height ) {
|
||||||
@@ -165,7 +170,7 @@ public class Camera extends Gizmo {
|
|||||||
super.update();
|
super.update();
|
||||||
|
|
||||||
if (followTarget != null){
|
if (followTarget != null){
|
||||||
panTarget = followTarget.center();
|
panTarget = followTarget.center().offset(centerOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (panIntensity > 0f){
|
if (panIntensity > 0f){
|
||||||
@@ -203,8 +208,16 @@ public class Camera extends Gizmo {
|
|||||||
panIntensity = 0f;
|
panIntensity = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCenterOffset( float x, float y ){
|
||||||
|
scroll.x += x - centerOffset.x;
|
||||||
|
scroll.y += y - centerOffset.y;
|
||||||
|
centerOffset.set(x, y);
|
||||||
|
panIntensity = 0f;
|
||||||
|
followTarget = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void snapTo(float x, float y ) {
|
public void snapTo(float x, float y ) {
|
||||||
scroll.set( x - width / 2, y - height / 2 );
|
scroll.set( x - width / 2, y - height / 2 ).offset(centerOffset);
|
||||||
panIntensity = 0f;
|
panIntensity = 0f;
|
||||||
followTarget = null;
|
followTarget = null;
|
||||||
}
|
}
|
||||||
@@ -214,7 +227,7 @@ public class Camera extends Gizmo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void panTo( PointF dst, float intensity ){
|
public void panTo( PointF dst, float intensity ){
|
||||||
panTarget = dst;
|
panTarget = dst.offset(centerOffset);
|
||||||
panIntensity = intensity;
|
panIntensity = intensity;
|
||||||
followTarget = null;
|
followTarget = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -764,6 +764,15 @@ public class GameScene extends PixelScene {
|
|||||||
|
|
||||||
if (scene == null) return;
|
if (scene == null) return;
|
||||||
|
|
||||||
|
//move the camera center up a bit if we're on full UI and it is taking up lots of space
|
||||||
|
if (scene.inventory != null && scene.inventory.visible
|
||||||
|
&& (uiCamera.width < 460 && uiCamera.height < 300)){
|
||||||
|
Camera.main.setCenterOffset(0, Math.min(300-uiCamera.height, 460-uiCamera.width) / Camera.main.zoom);
|
||||||
|
} else {
|
||||||
|
Camera.main.setCenterOffset(0, 0);
|
||||||
|
}
|
||||||
|
//Camera.main.panTo(Dungeon.hero.sprite.center(), 5f);
|
||||||
|
|
||||||
//primarily for phones displays with notches
|
//primarily for phones displays with notches
|
||||||
//TODO Android never draws into notch atm, perhaps allow it for center notches?
|
//TODO Android never draws into notch atm, perhaps allow it for center notches?
|
||||||
RectF insets = DeviceCompat.getSafeInsets();
|
RectF insets = DeviceCompat.getSafeInsets();
|
||||||
|
|||||||
Reference in New Issue
Block a user