In my 2D game, I am not sure about my FPS and my game frame update method. When I want it to print out, to check if it is working in the console, it never writes anything. Am I missing something?
public class Main extends JFrame implements Runnable{
private static final long serialVersionUID = 1L;
static boolean running = true;
/* My game fps */
public void run() {
int FRAMES_PER_SECOND = 25;
int SKIP_TICKS = 1000 / FRAMES_PER_SECOND;
long next_game_tick = System.currentTimeMillis();
long sleep_time = 0;
while(running){
updateGame();
System.out.println("game updated")
next_game_tick = SKIP_TICKS;
sleep_time = next_game_tick - System.currentTimeMillis();
if(sleep_time > 0){
try {
Thread.sleep(sleep_time);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args){
platform g = new platform();
g.setVisible(true);
g.setSize(900, 900);
g.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
g.setResizable(false);
(new Thread(new Main())).start();
}
private void updateGame() {
/*(e.g)all game code*/
}
}
and is my thread running correctly?