I thought my key input and/or image refreshing was bad, but I should have it perfect now. The movement engine/demo is very laggy.
When you move around, it gets about 2-3 fps. If you maximize the screen, it magically fixes it giving it the normal fps which is not laggy at all and appears extremely smooth.
Could someone please help me find out why it is a very nice movement engine…only after the JFrame is resized in any way?
I don’t think anyone can help you without a few more details. How are you rendering (AWT? JOGL directly? LWJGL directly? Something built on top of one of those?) How does your game loop work? (JOGL Animator? Active rendering? Handled by a library?)
First of all, if you’re character.setImg calls are loading the image each time, that’s the source of your problem. I doubt that is the problem though because it wouldn’t get faster when maximized.
That does absolutely nothing. Just call Thread.sleep. That isn’t the problem though.
You’re doing it backwards. You should slow down updating the game so that it occurs a certain number of times per second regardless of the machine’s processing power. And then draw the screen as often as possible. You’re doing the opposite. You want to change your code to the following:
Just so you know, checking whether the elapsed milliseconds is more than 17 or sleeping for 7 milliseconds is likely equivalent to 20 and 10 milliseconds on Windows computers because that’s as precise as the timer is. .
You should look into active rendering and use the BufferStrategy class (see the API). Switching to full-screen exclusive mode is a way to speed things up, but it seems clear that isn’t the problem for you. Your program’s simple enough that it shouldn’t run so slow.
Is your main loop being executed on the Event Queue thread? If so, that’s something you should avoid.
I added a map loader, and when I go into the new map and after it loads, it goes back to “lagg mode” until I play with the window size by dragging it around
I took the floor image out and then it is less laggy at startup, but still magically fixable for some reason into the laggless state when you play with the JFrame.
I’ll look into the stuff you recommended, but any other ideas?