Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Countdown Timer In-Game  (Read 741 times)
0 Members and 3 Guests are viewing this topic.
Offline olingalan

JGO n00b
*

Posts: 5



« on: 2012-01-31 03:02:47 »

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..
Offline Regenuluz

Jr. Member
**

Posts: 73
Medals: 1



« Reply #1 on: 2012-01-31 03:38:42 »

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. Smiley
Offline olingalan

JGO n00b
*

Posts: 5



« Reply #2 on: 2012-02-02 05:15:22 »

tnx for helping me out
Games published by our own members! Go get 'em!
Offline GabrielBailey74

Full Member
**

Posts: 157
Medals: 2


Owner of Elite Demons R.I.P


« Reply #3 on: 2012-02-04 02:46:39 »

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

Declare these variables:
1  
2  
3  
4  
   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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
   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.

Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.073 seconds with 19 queries.