Add FPS counter
This commit is contained in:
parent
48b2e8b96b
commit
add8b5670b
2 changed files with 18 additions and 1 deletions
|
@ -1,25 +1,43 @@
|
||||||
package dev.bangbang.loom;
|
package dev.bangbang.loom;
|
||||||
|
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.utils.ScreenUtils;
|
import com.badlogic.gdx.utils.ScreenUtils;
|
||||||
|
|
||||||
public class Game extends ApplicationAdapter {
|
public class Game extends ApplicationAdapter {
|
||||||
SpriteBatch batch;
|
SpriteBatch batch;
|
||||||
Texture img;
|
Texture img;
|
||||||
|
BitmapFont font;
|
||||||
|
OrthographicCamera camera;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create () {
|
public void create () {
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
img = new Texture("badlogic.jpg");
|
img = new Texture("badlogic.jpg");
|
||||||
|
font = new BitmapFont();
|
||||||
|
camera = new OrthographicCamera();
|
||||||
|
camera.setToOrtho(false, 1600, 900);
|
||||||
|
|
||||||
|
font.getData().setScale(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render () {
|
public void render () {
|
||||||
ScreenUtils.clear(1, 0, 0, 1);
|
ScreenUtils.clear(1, 0, 0, 1);
|
||||||
|
|
||||||
|
camera.update();
|
||||||
|
batch.setProjectionMatrix(camera.combined);
|
||||||
|
|
||||||
batch.begin();
|
batch.begin();
|
||||||
|
|
||||||
batch.draw(img, 0, 0);
|
batch.draw(img, 0, 0);
|
||||||
|
font.draw(batch, "FPS: " + Integer.toString(Gdx.graphics.getFramesPerSecond()), 5, 895);
|
||||||
|
|
||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ public class DesktopLauncher {
|
||||||
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
|
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
|
||||||
config.setWindowedMode(1600, 900);
|
config.setWindowedMode(1600, 900);
|
||||||
config.setForegroundFPS(60);
|
config.setForegroundFPS(60);
|
||||||
config.setIdleFPS(15);
|
|
||||||
config.useVsync(true);
|
config.useVsync(true);
|
||||||
config.setTitle("Loom");
|
config.setTitle("Loom");
|
||||||
new Lwjgl3Application(new Game(), config);
|
new Lwjgl3Application(new Game(), config);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue