Add debug info to bottom left of screen
This commit is contained in:
parent
5e3f71f236
commit
ed8c90be1a
@ -3,6 +3,8 @@ package com.me.brickbuster;
|
|||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.me.brickbuster.entity.*;
|
import com.me.brickbuster.entity.*;
|
||||||
@ -22,6 +24,9 @@ public class BrickBuster extends ApplicationAdapter {
|
|||||||
public static final Vector2 HORIZONTAL_EDGE = new Vector2(1, 0);
|
public static final Vector2 HORIZONTAL_EDGE = new Vector2(1, 0);
|
||||||
public static final Vector2 VERTICAL_EDGE = new Vector2(0, 1);
|
public static final Vector2 VERTICAL_EDGE = new Vector2(0, 1);
|
||||||
|
|
||||||
|
private BitmapFont font;
|
||||||
|
private SpriteBatch batch;
|
||||||
|
|
||||||
private Ball ball;
|
private Ball ball;
|
||||||
private Paddle paddle;
|
private Paddle paddle;
|
||||||
private ArrayList<Brick> bricks;
|
private ArrayList<Brick> bricks;
|
||||||
@ -30,6 +35,9 @@ public class BrickBuster extends ApplicationAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create () {
|
public void create () {
|
||||||
|
font = new BitmapFont();
|
||||||
|
batch = new SpriteBatch();
|
||||||
|
|
||||||
ball = new Ball(this);
|
ball = new Ball(this);
|
||||||
paddle = new Paddle(this);
|
paddle = new Paddle(this);
|
||||||
powerUps = new ArrayList<PowerUp>();
|
powerUps = new ArrayList<PowerUp>();
|
||||||
@ -52,21 +60,29 @@ public class BrickBuster extends ApplicationAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render () {
|
public void render () {
|
||||||
update(Gdx.graphics.getDeltaTime());
|
|
||||||
|
|
||||||
Gdx.gl.glClearColor(0.5f,1,1,1);
|
Gdx.gl.glClearColor(0.5f,1,1,1);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
long start_update = System.nanoTime();
|
||||||
|
update(Gdx.graphics.getDeltaTime());
|
||||||
|
long finish_update = System.nanoTime() - start_update;
|
||||||
|
|
||||||
|
long start_render = System.nanoTime();
|
||||||
for (Brick block : bricks) {
|
for (Brick block : bricks) {
|
||||||
block.render();
|
block.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PowerUp powerUp : powerUps) {
|
for (PowerUp powerUp : powerUps) {
|
||||||
powerUp.render();
|
powerUp.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
ball.render();
|
ball.render();
|
||||||
paddle.render();
|
paddle.render();
|
||||||
|
long finish_render = System.nanoTime() - start_render;
|
||||||
|
|
||||||
|
batch.begin();
|
||||||
|
//batch.setColor(Color.BLACK);
|
||||||
|
font.draw(batch, String.format("FPS: %d Update: %.2f ms Render: %.2f ms",
|
||||||
|
Gdx.graphics.getFramesPerSecond(), finish_update/1000000f, finish_render/1000000f), 0, 13);
|
||||||
|
batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(float dt) {
|
public void update(float dt) {
|
||||||
|
Loading…
Reference in New Issue
Block a user