v1.4.0: added a setting to adjust camera follow intensity

This commit is contained in:
Evan Debenham
2022-09-13 15:42:34 -04:00
parent 39fa4adbe1
commit 41ea6aad60
7 changed files with 102 additions and 55 deletions

View File

@@ -165,22 +165,47 @@ public class Camera extends Gizmo {
//camera moves at a speed such that it will pan to its current target in 1/intensity seconds
//keep in mind though that this speed is constantly decreasing, so actual pan time is higher
float panIntensity = 0f;
//what percentage of the screen to ignore when follow panning.
// 0% means always keep in the center, 50% would mean pan until target is within center 50% of screen
float followDeadzone = 0f;
@Override
public void update() {
super.update();
float deadX = 0;
float deadY = 0;
if (followTarget != null){
panTarget = followTarget.center().offset(centerOffset);
deadX = width * followDeadzone /2f;
deadY = height * followDeadzone /2f;
}
if (panIntensity > 0f){
PointF panMove = new PointF();
panMove.x = panTarget.x - (scroll.x + width/2f);
panMove.y = panTarget.y - (scroll.y + height/2f);
if (panMove.x > deadX){
panMove.x -= deadX;
} else if (panMove.x < -deadX){
panMove.x += deadX;
} else {
panMove.x = 0;
}
if (panMove.y > deadY){
panMove.y -= deadY;
} else if (panMove.y < -deadY){
panMove.y += deadY;
} else {
panMove.y = 0;
}
panMove.scale(Math.min(1f, Game.elapsed * panIntensity));
scroll.offset(panMove);
}
@@ -212,8 +237,10 @@ public class Camera extends Gizmo {
public void setCenterOffset( float x, float y ){
scroll.x += x - centerOffset.x;
scroll.y += y - centerOffset.y;
panTarget.x += x - centerOffset.x;
panTarget.y += y - centerOffset.y;
if (panTarget != null) {
panTarget.x += x - centerOffset.x;
panTarget.y += y - centerOffset.y;
}
centerOffset.set(x, y);
}
@@ -237,6 +264,10 @@ public class Camera extends Gizmo {
followTarget = target;
panIntensity = intensity;
}
public void setFollowDeadzone( float deadzone ){
followDeadzone = deadzone;
}
public PointF screenToCamera( int x, int y ) {
return new PointF(