Add FPS counter

This commit is contained in:
Sebastian Cabrera 2024-03-29 20:30:43 -04:00
parent 48b2e8b96b
commit add8b5670b
2 changed files with 18 additions and 1 deletions

View file

@ -1,25 +1,43 @@
package dev.bangbang.loom;
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.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.ScreenUtils;
public class Game extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
BitmapFont font;
OrthographicCamera camera;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
font = new BitmapFont();
camera = new OrthographicCamera();
camera.setToOrtho(false, 1600, 900);
font.getData().setScale(2);
}
@Override
public void render () {
ScreenUtils.clear(1, 0, 0, 1);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(img, 0, 0);
font.draw(batch, "FPS: " + Integer.toString(Gdx.graphics.getFramesPerSecond()), 5, 895);
batch.end();
}

View file

@ -9,7 +9,6 @@ public class DesktopLauncher {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setWindowedMode(1600, 900);
config.setForegroundFPS(60);
config.setIdleFPS(15);
config.useVsync(true);
config.setTitle("Loom");
new Lwjgl3Application(new Game(), config);