File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Jumpy program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jumpy program" Watch "Jumpy program" New topic
Author

Jumpy program

Ronan Jacksn
Greenhorn

Joined: Jul 22, 2011
Posts: 4
I'm trying to create a game in a JFrame and JPanel however the app's animation/movement is 'jumping' every 1/4 of a second and is annoyingly visible.

Game Thread:


Rendering


Is there something wrong with this update loop?

Thanks
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4640
    
    5

1. Never call setBackground(...) or otherwise change the state of any component in a painting method override.
2. Instead of a Thread with an infinite loop and a sleep(...) it's better you use a javax.swing.Timer. That's what the class is meant for.


luck, db
There are no new questions, but there may be new answers.
Ronan Jacksn
Greenhorn

Joined: Jul 22, 2011
Posts: 4
Thanks. I've moved the setBackground out of the paint function. What is wrong with a thread with an infinite loop? Still jumping so I assume it is because of this thread?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
You also need to work out how long timeLeft is. You will see jerkiness of you update less than about 40 times a second.
Ronan Jacksn
Greenhorn

Joined: Jul 22, 2011
Posts: 4
It's not constantly jerky. It goes smooth for about 3 seconds then jumps for a very small amount of time, then smooth for 3 seconds repeat etc...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jumpy program