I am working on a game that has a lot of time-passed checks of the following format. These work great, but there is a problem when the game is paused:
If paused for any meaningful amount of time, the if statement will become
true
.
const t = new Date().getTime(); // Get the current time (in ms)
const fireCooldown = 500; // The time to wait before firing again (in ms)
if(t > lastFireTime + fireCooldown) {
lastFireTime = t;
fire();
}
How can I integrate pause functionality into this - in a way where pausing does not make the if statement true
?