Add smoothed camera transitions
This commit is contained in:
parent
e5947d5936
commit
2d7024275f
1 changed files with 31 additions and 3 deletions
|
@ -14,13 +14,13 @@ import com.badlogic.gdx.maps.tiled.TmxMapLoader;
|
|||
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.redstrate.watersymbol.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public class GameScreen implements Screen {
|
||||
private final WaterSymbol game;
|
||||
|
@ -154,6 +154,8 @@ public class GameScreen implements Screen {
|
|||
currentTurn++;
|
||||
startNewTeamTurn(Unit.Team.Player);
|
||||
}
|
||||
} else {
|
||||
smoothlyTransitionCamera(new Vector3(currentUnit.positionX * 32, currentUnit.positionY * 32, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,12 +228,30 @@ public class GameScreen implements Screen {
|
|||
}
|
||||
}
|
||||
|
||||
Vector3 oldCameraPosition;
|
||||
Vector3 targetCameraPosition;
|
||||
float lerp = 0.0f;
|
||||
boolean currentlyTransitionCamera = false;
|
||||
|
||||
void smoothlyTransitionCamera(Vector3 to) {
|
||||
oldCameraPosition = camera.position;
|
||||
targetCameraPosition = to;
|
||||
lerp = 0.0f;
|
||||
currentlyTransitionCamera = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
ScreenUtils.clear(0, 0, 0.2f, 1);
|
||||
|
||||
if(currentUnit != null)
|
||||
camera.position.set(currentUnit.positionX * 32, currentUnit.positionY * 32, 0);
|
||||
if(currentlyTransitionCamera) {
|
||||
camera.position.set(oldCameraPosition.lerp(targetCameraPosition, lerp));
|
||||
lerp += delta;
|
||||
|
||||
if(camera.position.epsilonEquals(targetCameraPosition)) {
|
||||
currentlyTransitionCamera = false;
|
||||
}
|
||||
}
|
||||
|
||||
camera.update();
|
||||
tiledMapRenderer.setView(camera);
|
||||
|
@ -245,6 +265,12 @@ public class GameScreen implements Screen {
|
|||
playerSprite.draw(game.batch);
|
||||
}
|
||||
|
||||
// early exit, since we want the camera to finish it's nice transistion
|
||||
if(currentlyTransitionCamera) {
|
||||
game.batch.end();
|
||||
return;
|
||||
}
|
||||
|
||||
if(currentTurnTeam == Unit.Team.Player && currentUnit != null) {
|
||||
// player is trying to move
|
||||
if (Gdx.input.isButtonPressed(0) && !currentlyAwaitingAuxilaryAction) {
|
||||
|
@ -363,6 +389,8 @@ public class GameScreen implements Screen {
|
|||
Vector2 nextMove = currentMovementList.remove(0);
|
||||
currentUnit.positionX = (int) nextMove.x;
|
||||
currentUnit.positionY = (int) nextMove.y;
|
||||
|
||||
smoothlyTransitionCamera(new Vector3(currentUnit.positionX * 32, currentUnit.positionY * 32, 0));
|
||||
} else {
|
||||
currentlyTakingAction = false;
|
||||
currentlyAwaitingAuxilaryAction = true;
|
||||
|
|
Reference in a new issue