• Advertisement
Sign in to follow this  

Countdown timer

This topic is 4946 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to create a timer that countdowns from 30 seconds down to 0.How do i implement such a timer in my game loop which is a java thread.

Share this post


Link to post
Share on other sites
Advertisement
How often does the thread execute? I'm assuming you've got the thread timed so the game code "ticks" once every so often. If it's "ticking" every 10ms, just have a counter that starts at 0 and is incremented every "tick", wait for it to hit 100 then reset it and decrement your countdown variable.

Share this post


Link to post
Share on other sites
Hi!

Try this:

long t,current_time;

somewhere start your timer:
t = System.currentTimeMillis() + 30000;

....
in your game loop:

current_time = t - System.currentTimeMillis();

Regards
McMc

P.S. It's the first time i use my profile signature.... i am not sure about how it looks like.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement