Skip to content

Show FPS Counter

ImTallone edited this page Oct 16, 2018 · 4 revisions

FPS Counter

Here is the mini-tutorial for adding a simple fps counter in PowerHigh

You need to define a fpsCounter variable inside the class (Don't forget to import it!)

Text fpsCounter = new Text();

After you did that, put in init() method the code for just displaying a text:

import java.awt.Color;
/* ... */
fpsCounter.setColor(Color.WHITE);
fpsCounter.setText("FPS: ???");
fpsCounter.setX(5);
fpsCounter.setY(15);
win.add(fpsCounter);

If you test this, it will show: FPS: ???

To make the text updating, write in the update() method:

fpsCounter.setText("FPS: " + win.getFPS());

Done! If you test it, you will see the FPS Counter is updating!