Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add FPS indicator (label) to main game screen.

  • Loading branch information...
commit 34370f550da40ae692a176a9ce5d3ab2ea7dad7e 1 parent d997802
@santa4nt santa4nt authored
View
6 Tamagotchi/src/com/redditandroiddevelopers/tamagotchi/TamagotchiGame.java
@@ -9,7 +9,6 @@
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver;
import com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver.Resolution;
-import com.badlogic.gdx.graphics.FPSLogger;
import com.badlogic.gdx.graphics.Texture;
import com.redditandroiddevelopers.tamagotchi.screens.CommonScreen;
import com.redditandroiddevelopers.tamagotchi.screens.MainGameScreen;
@@ -38,8 +37,6 @@
public AssetManager assetManager;
public TamagotchiAssets assets;
- private FPSLogger fpsLogger; // XXX: temporary!
-
public TamagotchiGame(TamagotchiConfiguration config) {
this.config = config;
}
@@ -49,7 +46,6 @@ public void create() {
// do first-time configurations that should live as long as the
// application does
Gdx.app.setLogLevel(config.logLevel);
- fpsLogger = new FPSLogger();
// create screen objects we're going to need throughout
screens = new CommonScreen[] {
@@ -82,8 +78,6 @@ public void render() {
// actually render the current screen
super.render();
- if (config.logFps)
- fpsLogger.log();
}
/**
View
4 Tamagotchi/src/com/redditandroiddevelopers/tamagotchi/screens/CommonScreen.java
@@ -46,8 +46,10 @@ public void update(float delta) {
camera.update();
if (!Gdx.graphics.isGL20Available())
camera.apply(Gdx.gl10);
- else
+ else {
assert false; // not supporting GL20 yet
+ throw new UnsupportedOperationException("OpenGL ES 2.0");
+ }
}
/**
View
43 Tamagotchi/src/com/redditandroiddevelopers/tamagotchi/screens/MainGameScreen.java
@@ -2,6 +2,7 @@
package com.redditandroiddevelopers.tamagotchi.screens;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
@@ -10,6 +11,8 @@
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
+import com.badlogic.gdx.scenes.scene2d.ui.Label;
+import com.redditandroiddevelopers.tamagotchi.TamagotchiAssets.FontAsset;
import com.redditandroiddevelopers.tamagotchi.TamagotchiAssets.TextureAsset;
import com.redditandroiddevelopers.tamagotchi.TamagotchiGame;
import com.redditandroiddevelopers.tamagotchi.ui.DragListener;
@@ -24,6 +27,7 @@
private static final String TAG = "Tamagotchi:MainGameScreen";
+ private static final String GRP_UI = "ui";
private static final String GRP_TOP_BUTTONS = "top_buttons";
private static final String GRP_STATUS_PANEL = "status_panel";
private static final String GRP_CREATURE = "creature";
@@ -37,6 +41,7 @@
private Button[] buttons;
private DraggableImage btnDragDown;
+ private Label fpsLabel;
public MainGameScreen(TamagotchiGame game) {
super(game);
@@ -50,9 +55,12 @@ protected final Stage createStage(SpriteBatch batch) {
@Override
public final void show() {
super.show();
+ layout();
+ }
+ private void layout() {
// add groups for better readability and flexibility
- final Group ui = new Group("ui");
+ final Group ui = new Group(GRP_UI);
final Group topButtons = new Group(GRP_TOP_BUTTONS);
final Group statusPanel = new Group(GRP_STATUS_PANEL);
final Group creature = new Group(GRP_CREATURE);
@@ -68,11 +76,9 @@ public final void show() {
// set margin between buttons
final int marginBetweenButtons = 10;
-
// buttons have the same width and height. using this value allows
// precise placement of the buttons
final int width = buttonTexture.getWidth() + marginBetweenButtons;
-
buttons = new Button[NUM_BUTTONS];
for (int i = 0; i < NUM_BUTTONS; i++) {
final Button button = new Button(buttonTextureRegion);
@@ -84,7 +90,6 @@ public final void show() {
// adjust width of 'topButtons'
topButtons.width = width * topButtons.getActors().size();
-
// position topButtons in top right corner
topButtons.x = stage.right() - topButtons.width;
topButtons.y = stage.top() - width;
@@ -96,20 +101,40 @@ public final void show() {
btnDragDown.setDragListener(this);
statusPanel.addActor(btnDragDown);
+ // add an FPS label (subject to configuration)
+ if (game.config.logFps) {
+ final Label.LabelStyle labelStyle = new Label.LabelStyle(
+ game.assets.getAsset(FontAsset.DEFAULT),
+ Color.RED);
+ fpsLabel = new Label("FPS: " + Gdx.graphics.getFramesPerSecond(), labelStyle);
+ background.addActor(fpsLabel);
+ }
+
// TODO: Add basic status mockup that can be pulled down
// TODO: Position statusPanel in top left corner
+ // TODO: Add creature
+ // TODO: Add background
+ // TODO: Add layers for background and the main stage
+ // TODO: Add overlays, e.g. for speech bubbles
+
// add various groups to the 'ui' group
+ ui.addActor(background);
+ ui.addActor(creature);
ui.addActor(statusPanel);
ui.addActor(topButtons);
- // add the 'ui' to the stage
+ // add the 'ui' group to the stage
stage.addActor(ui);
+ }
- // TODO: Add creature
- // TODO: Add background
- // TODO: Add layers for background and the main stage
- // TODO: Add overlays, e.g. for speech bubbles
+ @Override
+ public void update(float delta) {
+ super.update(delta);
+ if (fpsLabel != null) {
+ assert game.config.logFps;
+ fpsLabel.setText("FPS: " + Gdx.graphics.getFramesPerSecond());
+ }
}
@Override
Please sign in to comment.
Something went wrong with that request. Please try again.