Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

How can I format the number of digits my stopwatch shows? [closed]

$
0
0

I have made a stopwatch that displays the time in seconds during my game in libgdx. At the moment it shows a bunch of digits after the decimal point as it runs. Does anyone know how to change it so it only shows the time to 3 decimal points?

Here is my Timer class:

public class Timer {
SpriteBatch sb;
private BitmapFont font;
private float deltaTime = 0;
CharSequence str;

public Timer() {
    font = TextureManager.font;
    sb = new SpriteBatch();

}

public void drawTime(SpriteBatch sb) {
    deltaTime += Gdx.graphics.getDeltaTime();
    str = Float.toString(deltaTime);
    font.draw(sb, str, 240 / 2 - 60, 400 / 2);
}

}

Thanks


Viewing all articles
Browse latest Browse all 434

Trending Articles