I'm doing a gameengine including a physics and graphics engine. Right now my graphics engine is set to 60 fps, and sometime i notice slow updates on the screen. I have a JFrame which i add a JPanel to which moves around, meaning the graphic engine does frame.repaint() every loop. I'm starting to believe that this repainting on the frame does the small delay on screen.
The delay is such that the JPanel moves in a straight line, and suddenly it can jump a bit further than usual.
Is it better to put a JPanel "gameField" on the JFrame and then add a JPanel "player" to the gameField and repaint the gameField instead? Or is it basically the same thing as repainting the JFrame? I just heard that the JFrame is supposed to be a heavy component.
I've tried setting higher fps, which changes nothing.
Have a look at this page here, it's a lot of reading but should contain most of what you need.
EDIT: This page here is a bit more succinct
This stack overflow post here deal's with double buffering.
The best advice i can give you though, is find a copy of 'Killer game programming in Java'. You can get old ebook versions for free off the net easily. A lot of the stuff is a bit dated, but the first few chapters, which deal with making a game loop and writing to a buffer are still very much relevant and will help you a great deal in the long run!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With