Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[java] Delay in Java


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 kino   Members   -  Reputation: 122

Like
0Likes
Like

Posted 13 April 2005 - 09:21 AM

Is there anything like the delay function in Java? I'm using this: try { Thread.sleep(long milliseconds); } catch(InterruptedException ie) { } Is there any other option? Thanks! Bye Bye!
Long live Rock!!

Sponsor:

#2 H_o_p_s   Members   -  Reputation: 877

Like
0Likes
Like

Posted 13 April 2005 - 07:44 PM

Thats the one that I use.... But you have to keep in mind that using Thread.sleep(); will make sure that it sleeps at least the long milliseconds. This means that if you want it to sleep 5 seconds, it will sleep five or more seconds.

If you want the thread to yeild to other threads (like in the main loop) use Thread.yeild().

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 13 April 2005 - 07:57 PM

I can't remember off the top of my head, but look up the Timer object. It can be used to delay animations and such.

#4 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 16 April 2005 - 02:36 AM

don;'t user Timer, it sucks (I've used it a lot). It's not fully implemented at the API level, and so it works so badly that it'll take you less time to do everything yourself.

#5 kino   Members   -  Reputation: 122

Like
0Likes
Like

Posted 18 April 2005 - 06:44 AM

Quote:
will make sure that it sleeps at least the long milliseconds


Didn’t know that about thread.sleep()… But how far goes this lack of precision, I mean, if I want the thread to sleep 1 second, 1000 milliseconds, would it keep sleeping until how much time?

Quote:
… look up the Timer object


It’s nice to know other ways to do something, and so is to get opinions from people who already tried them…

Thanks all !!


#6 H_o_p_s   Members   -  Reputation: 877

Like
0Likes
Like

Posted 18 April 2005 - 08:19 AM

Thread.sleep() is pretty acurate at higher values. If your using it in your game loop, and it needs to sleep ten milliseconds or less, it will be as much as five milliseconds or more off. This is caused by the different implementations of the internal system timer on different JRE on the different platforms.

I believe that XP, Linux, and MacOSX all have 1ms internal timers for the JRE, but when you get into some of the older Windows operating systems like Windows98 the system timer can be as bad as only updating every 50ms. This makes it so when you say Thread.sleep(1) it actually sleeps 50.

But all in all it is quite usable. I'm using it in my game which runs ~100fps and it doesn't make any messups (mind you I'm on OSX), but if your planning on having it wait something over than the 50ms your fins on any platform. 1 second sleeps should have no problem at all.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS