Original Post
🔒 Locked
countdown timer
Advertisement
Write a function that gets the current system time from an abtracting API (if you use one) or the underlying OS. (You haven't told us what you use, so we can't tell you how it could work in more detail.) Return the time value converted to seconds.
Before entering the game loop, invoke the above function to get the game start moment. Then inside the game loop use it again to get the current moment. Compute the difference and break the loop (i.e. stop the game) if the difference is greater than N.
Alternatively for a "real" countdown, e.g. if you want to display the remaining time, add N to the start moment value before entering the game loop. Then subtract the current moment inside the loop.
Before entering the game loop, invoke the above function to get the game start moment. Then inside the game loop use it again to get the current moment. Compute the difference and break the loop (i.e. stop the game) if the difference is greater than N.
Alternatively for a "real" countdown, e.g. if you want to display the remaining time, add N to the start moment value before entering the game loop. Then subtract the current moment inside the loop.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement