How to implement a timer?

Hello,
I am trying to let my teapot fly and when it stops it shoul wait 5 sec bevor it starts. I tried this:

[java]
float lastUpdate = 5f;
float time = Timer.getTime().getTimeInSeconds();

if (lastUpdate <= time){
playing = true;
motionControl.play();
[/java]

But it says
[java] Timer.getTime().getTimeInSeconds();
[/java]

is not posible. Any idea why?

Thanks for your help!

as far as I am concerned I don’t see any of those methods if you use this Timer class
http://docs.oracle.com/javase/7/docs/api/java/util/Timer.html

@weave
getTimeInSeconds returns the time elapsed in second since 1 january 1970, there is a slight chance that it’s always greater than 5 seconds.

Don’t use jme Timer, you don’t need to. Make a control, add it to your teapot, and in the update(float tpf) method stack the tpf in a time variable.

oh missed the jme class (http://hub.jmonkeyengine.org/javadoc/com/jme3/system/Timer.html)

@nehon
is there any difference to System.currentTimeMillis() then?

Could you give me an example? I have no idea where to put the update method in my code! :S

[java]
inputManager.addMapping(“play_stop”, new KeyTrigger(KeyInput.KEY_1));

    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {

// float lastUpdate = 5f;
// float time = Timer.getTime().getTimeInSeconds();

            if (name.equals("play_stop") &amp;&amp; keyPressed) {
                if (playing) {
                    playing = false;
                    motionControl.pause();
                   
                } else {
                    playing = true;
                    motionControl.play();
                }
           
            }
        }
       };

[/java]
Thanks

@nehon said: Don't use jme Timer, you don't need to. Make a control, add it to your teapot, and in the update(float tpf) method stack the tpf in a time variable.

I am new here so may be I am now saing bulsh**, but why not using the standart Timer class from Java?

@gtafan said: I am new here so may be I am now saing bulsh**, but why not using the standart Timer class from Java?

Your game is constantly being polled with time information. Why involve something more complicated than time += tpf?

@pspeed said: Your game is constantly being polled with time information. Why involve something more complicated than time += tpf?
I am not a fan of buisy waiting, and topicstarter was asking about timer.
@gtafan said: I am not a fan of buisy waiting, and topicstarter was asking about timer.

It’s not really about busy waiting. Games by there nature are polled all over the place once per frame. Why bring extra complexity, event creation, etc. in to just to count some time? Thus the suggestion to just add a control that counts time until you want to remove it.

Somehow that Timer is going to have to sync in with the game thread somehow. Lots of trouble for a simple thing.

@pspeed said: It's not really about busy waiting. Games by there nature are polled all over the place once per frame. Why bring extra complexity, event creation, etc. in to just to count some time? Thus the suggestion to just add a control that counts time until you want to remove it.

Somehow that Timer is going to have to sync in with the game thread somehow. Lots of trouble for a simple thing.


The only problem with your solution is, that on diferent systems it works diferent.

@gtafan said: The only problem with your solution is, that on diferent systems it works diferent.

??? What different systems? I either don’t understand what you mean by ‘system’ or you are talking complete nonsense.

@pspeed said: ??? What different systems? I either don't understand what you mean by 'system' or you are talking complete nonsense.
I mean hardware and software.

Stop trolling pspeed, he’s a nice guy :slight_smile:

@jmaasing said: Stop trolling pspeed, he's a nice guy :-)
Nobody ist trolling pspeed.
@gtafan said: I mean hardware and software.

Then you are talking complete nonsense because there is nothing system dependent in accumulating tpf as time.

@pspeed said: Then you are talking complete nonsense because there is nothing system dependent in accumulating tpf as time.
You cann´t have the same fps rate on single core processor and onboard grafphics and quad core processor and geforce grphics.

TPF is the “time in seconds since last frame”.

That’s all. I’m out of here.

@gtafan said: You cann´t have the same fps rate on single core processor and onboard grafphics and quad core processor and geforce grphics.

tpf is frame rate dependent… it’s the whole point.

It’s tough to have discussions with someone who doesn’t even bother to learn what they are discussing. :confused:

@pspeed said: tpf is frame rate dependent... it's the whole point.

It’s tough to have discussions with someone who doesn’t even bother to learn what they are discussing. :confused:


I thoght we were tallking about fps and tpf means the same. Such misunderstending can hapen if using foring language. We were talking about diferent things, sory.