Skip to main content
added 3 characters in body
Source Link

You first need to start with creating your game loop. Consider something like this below. It will loop every second by default(60fps), but you're able to adjust this. Now areyou're able to keep checking for your .Pak file(s) in the render() loop.

You first need to start with creating your game loop. Consider something like this below. It will loop every second by default(60fps), but you're able to adjust this. Now are able to keep checking for your .Pak file(s) in the render() loop.

You first need to start with creating your game loop. Consider something like this below. It will loop every second by default(60fps), but you're able to adjust this. Now you're able to keep checking for your .Pak file(s) in the render() loop.

added 2 characters in body
Source Link

You first need to start with creating your game loop. Consider something like this below. It will loop every second by default(60fps), but you're able to adjust this. Now are able to keep checking for your .Pak file(s) in the tickrender() loop.

You first need to start with creating your game loop. Consider something like this below. It will loop every second by default(60fps), but you're able to adjust this. Now are able to keep checking for your .Pak file(s) in the tick() loop.

You first need to start with creating your game loop. Consider something like this below. It will loop every second by default(60fps), but you're able to adjust this. Now are able to keep checking for your .Pak file(s) in the render() loop.

Source Link

You first need to start with creating your game loop. Consider something like this below. It will loop every second by default(60fps), but you're able to adjust this. Now are able to keep checking for your .Pak file(s) in the tick() loop.

    public class Game {

 static boolean running = false;
 private Thread thread;
 

private Game(){

    //no other functions should be here
    initializeGame();
}


private void initializeGame() {
    //Create your game objects and get input    
}

private synchronized void startGame() {
    if(running){
        System.out.println("[DEBUG] Already running");
        return;
    }
    
    thread = new Thread();
    running = true;
    thread.start(); 
    run();
}

public void run(){
    long lastTime = System.nanoTime();
    final double ticks = 60.0;
    double ns = 1000000000 / ticks;
    double delta = 0;
    int updates = 0;
    int frames = 0;
    long timer = System.currentTimeMillis();

    //Game Loop
    while(running){
        
        long now = System.nanoTime();
        delta += (now - lastTime)/ns;
        lastTime = now;
        
        if(delta >= 1){
            tick();
            delta--;
            updates++;
        }
        render();
        frames++;
        
        if(System.currentTimeMillis() - timer >= 1000){
            timer += 1000;

            frames = 0;
            updates = 0;    
        }
    }
    stop();
}

//Everything that updates
private void tick(){
    

}
//Everything that renders 
private void render(){
    
}
    
private synchronized void stop() {
    if(!running){
        return;
    }
    
    running = false;
    try{
        //Pause thread
        thread.join();
    }catch(InterruptedException e){
        e.printStackTrace();
    }
    System.exit(1);
    
}

public static void main(String []args){
    
    Game game = new Game();
    game.startGame();
    
}

}