It's my game loop code:
public void run() {
running = true;
boolean renderCheck = false;
double firstTime = 0;
double lastTime = System.nanoTime() / 1000000000.0;
double passedTime = 0;
double unprocessedTime = 0;
double frameTime = 0;
int frames = 0;
int fps = 0;
while (running) {
firstTime = System.nanoTime() / 1000000000.0;
passedTime = firstTime - lastTime;
lastTime = firstTime;
unprocessedTime += passedTime;
frameTime += passedTime;
while (unprocessedTime >= UPDATE_CAP) {
tick();
unprocessedTime -= UPDATE_CAP;
renderCheck = true;
}
if (frameTime >= 1.0) {
frameTime = 0;
fps = frames;
frames = 0;
System.out.println(fps);
}
if (renderCheck) {
render();
frames++;
renderCheck = false;
} else {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
It's a render zone:
private void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
this.createBufferStrategy(3);
return;
}
Graphics graphics = bs.getDrawGraphics();
graphics.setColor(Color.black);
graphics.fillRect(0, 0, WIDTH, HEIGHT);
handler.render(graphics);
graphics.dispose();
bs.show();
}
And here is a tick part(it's not necessary to show other code for handler because it'll be so much to read):
private void tick() {
handler.tick();
}
So the main problem is in the next thing. When i press the button my character has to start moving. And, actually, it does but with some delays which make this process look terrible. Than after a second, all is going perfectly. (I've already checked CPU loading - all goes normal)
This problem is happening only on linux PC. I've checked it on Windows 10 in exe format and all was working fine! That's a bit weird.
Soo, finally i found a solution for fixing this issue!
Just set system properties to java2d in your static main method by writing this code: