Countdown Timer In-Game

Hi guys! I’m a computer science student and my partner(in thesis) and I are developing a game ung JAVA NETBEANS IDE…

We wonder if u can help us out in choosing or giving us hint on how we can put A COUNTDOWN TIMER inside our game… Our game is composed of 4 time attack games so we need it badly…

tnx guys, hope u can help us out…

Just use a Timer. Java has those build in.

http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Timer.html

That should get you going in the right direction. :slight_smile:

tnx for helping me out

This would work, call this method where ever you handle your MAIN game cycle:

Declare these variables:


	private static int currentFPS = 0;
	public static int Fps; //Actual frames per second
	private static long start = 0;
	public static int levelTime = 120; //120 seconds = 2 minutes

Add this method:


	public static void updateFps() {
		currentFPS++;
		if (System.currentTimeMillis() - start >= 1000) { 
			levelTime -= 1; //We deduct 1 second, every second.
			Fps = currentFPS;
			currentFPS = 0;
			start = System.currentTimeMillis();
		}
	}

Works fine, every second (1000 milliseconds, its removing 1 from that levelTime, which you could draw out like "Time remaining: "+levelTime.
Hope it helps m8.