1

The function is not working any idea how to fix this. If it helps I am using this tutorial.

public void run() {
    long lastTime = System.nanoTime();
    double amountOfTicks = 60.0;
    double ns = 1000000000 / amountOfTicks;
    double delta = 0;
    long timer = System.currentTimeMillis();
    int frames = 0;
    while (running) {
        long now = System.nanoTime();
        delta += (now - lastTime) / ns;
        lastTime = now;
        while (delta >= 1) {
            tick();
            delta--;
        }
        if (running) {
            render();
            frames++;

            if (System.currentTimeMillis() - timer > 1000) {
                timer += 1000;
                System.out.println("FPS: " + frames);
                frames = 0;
            }
        }
        stop();
    }

    private void tick(); {

    }

    private void render(); {
        BufferStrategy bs = this.getBufferStrategy();
        if (bs == null) {
            this.createBufferStrtegy(3);
            return;
        }

        Graphics g = bs.getDrawGraphics();



        g.dispose();
        bs.show();
    }

}
2
  • What do you mean by not working? Commented Aug 1, 2015 at 9:10
  • 1. when I hover over private void it comes up with "Syntax error on token(s), misplaced construct(s)" 2.WHen I hover over tick/render it comes up with"The method tick() is undefined for the type Game" but isnt that defining it there? In the tutorial I used it worked fine for him either I missed something or my computer is just messed up
    – JudasMoses
    Commented Aug 1, 2015 at 9:12

1 Answer 1

0

Move your tick() and render() methods out of the run() method and remove semicolons from methods declarations.

public void run() {
    long lastTime = System.nanoTime();
    double amountOfTicks = 60.0;
    double ns = 1000000000 / amountOfTicks;
    double delta = 0;
    long timer = System.currentTimeMillis();
    int frames = 0;
    while (running) {
        long now = System.nanoTime();
        delta += (now - lastTime) / ns;
        lastTime = now;
        while (delta >= 1) {
            tick();
            delta--;
        }
        if (running) {
            render();
            frames++;

            if (System.currentTimeMillis() - timer > 1000) {
                timer += 1000;
                System.out.println("FPS: " + frames);
                frames = 0;
            }
        }
        stop();
    }
}

private void tick() {

}

private void render() {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
        this.createBufferStrtegy(3);
        return;
    }
    Graphics g = bs.getDrawGraphics();
    g.dispose();
    bs.show();
}
1
  • No I cant do that because when I dont have the semicolons it says it needs them there, thats why I put it there in the first place. @MazzCris
    – JudasMoses
    Commented Aug 1, 2015 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.