Countdown timer
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement