I have a big problem with my Java games. In every game I make the movement of the player and objects just looks awfull. The framerate is 60 fps without any problems. But the movement looks extremly unsmooth. I tried several things but nothing worked. The game code is too long and unstructured to show the hole one but here are some parts that may cause the problem:
this.repaint();
//Framerate
try {
Thread.sleep(15);
} catch (InterruptedException e) {
e.printStackTrace();
}
and that's how I tested the framerate:
//FPS anzeigen
if(RaumNr >= 0){
FPSCount += timesincelastframe;
howoften ++;
if(FPSCount > 1){
FPSCount = 0;
FPS = howoften;
howoften = 0;
System.out.println(FPS);
}
}
That's how my delta time system works:
while(true){
long thisframe = System.currentTimeMillis();
timesincelastframe = ((float) (lastframe - thisframe)) / -1000f;
lastframe = thisframe;
if(!M.hasFocus())
M.requestFocus();
and so on.
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.scale(BreiteMulti, HöheMulti);
And that's how I move the player for example:
x -= 350 * timesincelastframe * speed;
I hope you have any ideas wht the problem might be. If you need more code examples please tell me.
timesincelastframe
is constantly at 0.0166666667 seconds? Also a picture is worth a thousand words, you might want to use a tool such as gifcam or screentogif to upload an animated screenshot to your question so that it helps us see the issue. \$\endgroup\$