Skip to content
Snippets Groups Projects
Commit dadb8685 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko
Browse files

#591 Added pausing/resuming animation and animation sound on screen pause/resume event.

parent 0a2c84c1
Branches
Tags
No related merge requests found
......@@ -171,6 +171,7 @@ public class PursuitGame extends AbstractTablexiaGame<Void> {
private Vehicle vehicle;
private Image finishFlag;
private VehicleMoveAction vehicleMoveAction;
@Override
protected Viewport createViewport() {
......@@ -440,8 +441,8 @@ public class PursuitGame extends AbstractTablexiaGame<Void> {
final Music vehicleSound = getVehicleSound(Maps.getMapByNumber(mapNumber).getVehicleType());
final CatmullRomSpline<Vector2> path = new CatmullRomSpline<Vector2>(PursuitPositionDefinition.getPointsWithRotation(PursuitPositionDefinition.values()[mapNumber],grid.getRotation()),false);
VehicleMoveAction vehicleMoveAlongAction = new VehicleMoveAction(path, ANIMATION_MOVING_DURATION, grid.getWidth(), vehicleSound);
vehicle.addAction(Actions.sequence(Actions.show(),Actions.delay(ANIMATION_DELAY_DURATION),vehicleMoveAlongAction,new RunnableAction() {
vehicleMoveAction = new VehicleMoveAction(path, ANIMATION_MOVING_DURATION, grid.getWidth(), vehicleSound);
vehicle.addAction(Actions.sequence(Actions.show(),Actions.delay(ANIMATION_DELAY_DURATION),vehicleMoveAction,new RunnableAction() {
@Override
public void run() {
vehicleSound.dispose();
......@@ -456,6 +457,18 @@ public class PursuitGame extends AbstractTablexiaGame<Void> {
}));
}
@Override
protected void gamePaused(Map<String, String> gameState) {
super.gamePaused(gameState);
if (vehicleMoveAction!=null) vehicleMoveAction.pause();
}
@Override
protected void gameResumed() {
super.gameResumed();
if (vehicleMoveAction!=null) vehicleMoveAction.resume();
}
@Override
protected List<SummaryMessage> getSummaryMessageForGameResult(Game game) {
return Arrays.asList(new SummaryMessage(SummaryImage.TIME, getFormattedText(SUMMARY_TEXT_TIME, getOverallTimeText(GameDAO.getGameDuration(game)))),
......
......@@ -13,6 +13,8 @@ public class VehicleMoveAction extends MoveAlongAction {
private float parentSize;
private Path<Vector2> path;
private Music vehicleMusic;
private boolean acting = true;
public VehicleMoveAction(Path<Vector2> path, float duration, float parentSize, Music vehicleMusic) {
super(path, duration);
setRotate(true);
......@@ -31,6 +33,11 @@ public class VehicleMoveAction extends MoveAlongAction {
actor.setRotation(path.derivativeAt(value, percent).angle() - 90);
}
@Override
public boolean act(float delta) {
if (acting) return super.act(delta);
else return false;
}
@Override
protected void begin() {
......@@ -44,6 +51,17 @@ public class VehicleMoveAction extends MoveAlongAction {
protected void end() {
vehicleMusic.stop();
super.end();
acting = false;
}
public void pause(){
acting = false;
vehicleMusic.pause();
}
public void resume(){
acting = true;
vehicleMusic.play();
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment