Game Timer

Hi All,



I'm relatively new to the jMonkeyengine and I was wondering if someone would be able to help with my problems

I've been trying to develop a timer in my game to time how long the player takes to perform a task. I've written the following code:



1.private void timeGame(){

2. Text time;

3. Node timerNode = new Node();

4. for(int start=0;start<99;start++){

5. time = new Text("Time", "Time Elapsed: " + start);

6. time.setLocalTranslation(new Vector3f(600,10,0));

7. timerNode.attachChild(time);

8. fpsNode.attachChild(timerNode);

9. try {

10. Thread.sleep(1000);

11. } catch (InterruptedException e) {

12. e.printStackTrace();

13. }

14. time = new Text("Time", "Time Elapsed:

Please don’t cross post:



http://www.jmonkeyengine.com/jmeforum/index.php?topic=4577

Sorry, I just wasn't sure what heading my question came under. Won't happen again. :S

Instead of creating and attaching new text objects, use a single Text object and use the print method to change the text.

The superimposing problem is fixed now, however when the game starts, the screen remains blank until the timer finishes and then the game environment appears with the limit time i.e. it iterates to the end of the timer. I can see from the moving scroller in the Console window of Eclipse that the timer is runinng properly though.



Where should I position my "timeGame()" method so that it counts during the game? simpleInitGame? simpleUpdate?



Thanks

:smiley:

The easiest way would be to simply use a Thread. :o

Or swap out and use StandardGame as-is and it will just work. :wink:

Seems daft to have multiple timers - why dont you look to extends the LWJGLTimer and implement an alarm mechanism, ie - register something with the timer that that will be invoked when time elapsed = x