I am creating a simple game using Java. I'm not using any game library. I just want to know if it is okay to call Thread.sleep(40) before calling repaint().
public void run() { while(isGameRunning) { try { Thread.sleep(40); repaint(); } catch(Exception e) { } } } or should I use:
private long last_time = System.nanoTime(); private double ns = 1000000000/25D; private double delta = 0; @Override public void run() { while(Universe.IsGameRunning) { long time = System.nanoTime(); delta += (int)(time - last_time)/ns; last_time = time; System.out.println(delta); if(delta>=1) { repaint(); delta--; } } } The code below has more CPU and RAM usage than the first one. Can you explain to me how 'Delta Timing' actually works?
