Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jumpy program

 
Ronan Jacksn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ronan Jacksn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50224
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic