summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-30 22:04:38 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-30 22:04:38 +0200
commitfbb91b22c5bcbc22a83aeda96e9992bf786c2f97 (patch)
tree4478d19a5b09b15dc2b465bd70c385c1f86471f9 /core/src/ch/asynk
parent0b3f7e947212d7efc7690870b2ea06295c9b4ecd (diff)
downloadRustAndDust-fbb91b22c5bcbc22a83aeda96e9992bf786c2f97.zip
RustAndDust-fbb91b22c5bcbc22a83aeda96e9992bf786c2f97.tar.gz
add game/Hud
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java33
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java20
2 files changed, 37 insertions, 16 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
new file mode 100644
index 0000000..8fa2b32
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -0,0 +1,33 @@
+package ch.asynk.tankontank.game;
+
+import com.badlogic.gdx.Gdx;
+
+import com.badlogic.gdx.scenes.scene2d.Stage;
+import com.badlogic.gdx.scenes.scene2d.ui.Label;
+
+import com.badlogic.gdx.utils.viewport.Viewport;
+
+import ch.asynk.tankontank.TankOnTank;
+
+public class Hud extends Stage
+{
+ private final TankOnTank game;
+ private Label fps;
+
+ public Hud(final TankOnTank game, Viewport viewport)
+ {
+ super(viewport);
+ this.game = game;
+
+ fps = new Label("FPS: 0", game.skin);
+ fps.setPosition( 10, Gdx.graphics.getHeight() - 40);
+ addActor(fps);
+ }
+
+ @Override
+ public void act(float delta)
+ {
+ super.act(delta);
+ fps.setText("FPS: " + Gdx.graphics.getFramesPerSecond());
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index 764ff37..e7af833 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -17,9 +17,6 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
-import com.badlogic.gdx.scenes.scene2d.Stage;
-import com.badlogic.gdx.scenes.scene2d.ui.Label;
-
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
@@ -29,10 +26,10 @@ import com.badlogic.gdx.utils.viewport.ScreenViewport;
import ch.asynk.tankontank.TankOnTank;
+import ch.asynk.tankontank.game.Hud;
+import ch.asynk.tankontank.game.Map;
import ch.asynk.tankontank.game.GameFactory;
import ch.asynk.tankontank.game.GameFactory.UnitType;
-
-import ch.asynk.tankontank.game.Map;
import ch.asynk.tankontank.engine.Board;
import ch.asynk.tankontank.engine.Pawn;
@@ -58,9 +55,7 @@ public class GameScreen implements Screen
private final TankOnTank game;
private GameFactory factory;
private Map map;
-
- private Label fps;
- private Stage hud;
+ private Hud hud;
private Vector2 screenToWorld = new Vector2(); // ratio
private Vector3 touchPos = new Vector3(); // world coordinates
@@ -74,8 +69,7 @@ public class GameScreen implements Screen
factory = new GameFactory(game.manager);
- fps = new Label("FPS: 0", game.skin);
- fps.setPosition( 10, Gdx.graphics.getHeight() - 40);
+ hud = new Hud(game, new ScreenViewport());
map = factory.getMap(game.manager, GameFactory.MapType.MAP_A);
virtualWidth = map.getWidth();
@@ -108,9 +102,6 @@ public class GameScreen implements Screen
addUnit(9, 1, o, UnitType.US_SHERMAN_HQ);
addUnit(8, 0, o, UnitType.US_WOLVERINE);
- hud = new Stage(new ScreenViewport());
- hud.addActor(fps);
-
Gdx.input.setInputProcessor(getMultiplexer());
}
@@ -206,8 +197,6 @@ public class GameScreen implements Screen
cam.update();
- fps.setText("FPS: " + Gdx.graphics.getFramesPerSecond());
-
map.animate(delta);
mapBatch.setProjectionMatrix(cam.combined);
@@ -232,7 +221,6 @@ public class GameScreen implements Screen
public void resize(int width, int height)
{
// Gdx.app.debug("GameScreen", "resize (" + width + "," + height + ")");
- hud.getViewport().update(width, height);
mapViewport.update(width, height);
maxZoomOut = Math.min((map.getWidth() / cam.viewportWidth), (map.getHeight() / cam.viewportHeight));