6 Replies - 598 Views - Last Post: 08 October 2012 - 08:23 PM Rate Topic: -----

#1 Lagaam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 05-October 12

Using Thread but should I use swing.Timer?

Posted 08 October 2012 - 09:46 AM

Currently, for my 2D game engine I use Thread.sleep() for my delay, however I've gotten feed back that my delay might drift a bit, so should I try and switch to swing.Timer?
Is This A Good Question/Topic? 0
  • +

Replies To: Using Thread but should I use swing.Timer?

#2 CasiOo  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1406
  • Posts: 3,121
  • Joined: 05-April 11

Re: Using Thread but should I use swing.Timer?

Posted 08 October 2012 - 09:52 AM

swing timer is even worse. The util timer tries to even itself out over time, and will work much better :)

You could use Thread.sleep, so do I in my own game engine, but you just have to find a solution to the problems I wrote to you in the other topic. System.nanoTime() may be useful when adjusting the sleeping time.
You don't have to do any adjustments if you simply dont care, your game will still work.
Was This Post Helpful? 0
  • +
  • -

#3 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 850
  • View blog
  • Posts: 2,597
  • Joined: 29-July 11

Re: Using Thread but should I use swing.Timer?

Posted 08 October 2012 - 10:24 AM

Is your game really that fast paced that you need to worry about it? Would you even notice, or would it even affect game play? I doubt it. For most 2D games that aren't really that fast paced, and don't require big amounts of processing, I'd use a swing timer, as it is nice and simple. Your timer will call actionPerformed() roughly x after the end of the previous.

If I were using a thread, I would use a thread with a small, fixed sleep time of 2 or 3ms, then update your game logic and objects based on how much time has passed.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Using Thread but should I use swing.Timer?

Posted 08 October 2012 - 12:04 PM

Just keep in mind that is useless to repaint the sceen faster than every 16.666 millisecond as this is the frequency at which the screen hardware is refreshed
Was This Post Helpful? 1
  • +
  • -

#5 grimpirate  Icon User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 714
  • Joined: 03-August 06

Re: Using Thread but should I use swing.Timer?

Posted 08 October 2012 - 03:23 PM

That's only if you have a 60 Hz screen no pbl? Some screens support refresh rates of 75 and 80 Hz I believe.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Using Thread but should I use swing.Timer?

Posted 08 October 2012 - 03:38 PM

CPU speed has increased by a few hundred thousand in the last 30 years
MEMORY speed has increased by thousand in the last 30 years
DISK access speed has increased by a few hundred in the last 30 years
nobody bother increasing video refresh rate because the human eyes won't perceive the difference anyhow so why investing in increasing that speed
From an hardware point of view it is so simple to synchronize the refresh rate with the alternative current cycle that nobody ever looked for another solution
so 60/sec in North America 55/sec in Europe
Was This Post Helpful? 0
  • +
  • -

#7 grimpirate  Icon User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 714
  • Joined: 03-August 06

Re: Using Thread but should I use swing.Timer?

Posted 08 October 2012 - 08:23 PM

I can totally tell the difference on the 60 Hz and 120 Hz TVs when watching a Blu-Ray, but I concur with your point pbl as it makes a lot of sense in that regard.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1