How to render things expressed in seconds

86 views Asked by At

So basically, I'm making a simple pong game. You can see I made it so that everytime the ball collides with something, a hitmarker appears for a moment. But isnt this moment only one frame? Since render gets called a x times amount per second, while x is the fps. So what I realised is, what if someone who plays this game, plays with a slower framerate, then the hitmarker will be displayed longer.

TL;DR How do I let something render for a certain amount in seconds instead of frames, so that ppl with different fps get to see the image for the same amount of time.

Core: http://pastebin.com/QrJUxusR

Desktop: http://pastebin.com/i0w4H4Wq

Dew class: http://pastebin.com/wuPnUBbg

1

There are 1 answers

0
TomGrill Games On BEST ANSWER

You need to store the time when you did draw the hitmarker the first time plus the time how long it should be drawn in milliseconds. Now you know that you can draw the hitmarker as long the stored time is greater than the current time..

Pseudo code:

private long hitmarkerDrawStart;

if(collission) {
 hitmarkerDrawStart = TimeUtils.millis() + 1000; // 1000ms = 1s
}

public void render() {
 if(hitmarkerDrawStart > TimeUtils.millis()) {
//draw the hitmarker batch.draw(...)
}

}