I'm making an RPG-like 2D game from scratch with Java.
By now I'm in a pretty advanced stage with my game, but I encountered a problem- my game using too much CPU.
I know it's because my game loop doesn't use Thread.sleep. I looked for a solution on the internet but most of the answers were "you should move to LWJGL or LIBGDX". I also didn't find any good advice for using Thread.sleep in my game loop.
So, should I move my platform to some of those libraries, or could someone give me some advice how to deal with my CPU usage problem?
Here is my game loop:
public void run(){ int fps = 60; double timePerTick = 1000000000 / fps; double delta = 0; long now; long lastTime = System.nanoTime(); while (running){ now = System.nanoTime(); delta += (now - lastTime) / timePerTick; lastTime = now; if (delta >= 1) { tick(); render(); delta--; } } stop(); } I will just mention that I don't think that moving to one of those libraries will make things easier in the future, and that's because I'm in a pretty advanced stage in my game.
