Created
August 10, 2020 03:17
-
-
Save cypherdare/c22f1e29152cd4e8d629c835001adfc6 to your computer and use it in GitHub Desktop.
Minimal LibGDX FPS counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cyphercove.example; | |
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.scenes.scene2d.Stage; | |
import com.badlogic.gdx.scenes.scene2d.ui.Label; | |
import com.badlogic.gdx.scenes.scene2d.ui.Skin; | |
import com.badlogic.gdx.scenes.scene2d.ui.Table; | |
import com.badlogic.gdx.utils.viewport.ScreenViewport; | |
public class Simple extends ApplicationAdapter { | |
Stage stage; | |
Skin skin; | |
Label label; | |
int lastFps; | |
@Override | |
public void create() { | |
stage = new Stage(new ScreenViewport()); | |
skin = new Skin(Gdx.files.internal("uiskin.json")); | |
Table table = new Table(); | |
table.setFillParent(true); | |
label = new Label("", skin); | |
table.add(label); | |
stage.addActor(table); | |
} | |
@Override | |
public void resize(int width, int height) { | |
stage.getViewport().update(width, height, true); | |
} | |
@Override | |
public void render() { | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
int fps = Gdx.graphics.getFramesPerSecond(); | |
if (fps != lastFps) { | |
label.setText("" + fps); | |
lastFps = fps; | |
} | |
stage.act(); | |
stage.draw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment