简体   繁体   中英

System.out.println() breaks my if statement

I'm making the game dots, were you draw dots, connect them to make boxes. I have it so once you've clicked, the line follows your mouse. When you click on another dot it drops it there. When you add the println code in the if statement, the line no longer follows the mouse.

I have the following code:

public void run() {
    gp.initialize();
    while(isRunning) {
        if(gp.isLineDrag()) {
            previousTimeMil = System.nanoTime();
            update();
            draw();
            currentTimeMil = System.nanoTime();

        }
    }
}

Update: Sorry, here are the examples

This won't work,

public void run() {
    gp.initialize();
    while(isRunning) {
        if(gp.isLineDrag()) {
            System.out.println("Hi");
            previousTimeMil = System.nanoTime();
            update();
            draw();
            currentTimeMil = System.nanoTime();

        }
    }
}

This will work

public void run() {
    gp.initialize();
    while(isRunning) {
        System.out.println("I work now!");
        if(gp.isLineDrag()) {
            System.out.println("Hi");
            previousTimeMil = System.nanoTime();
            update();
            draw();
            currentTimeMil = System.nanoTime();

        }
    }
}

Thanks for all the help, hopefully next time I can ask a proper question.

This is a problem that often trips up people. You are running your program from Eclipse or a similar IDE that captures System.out into a text area. This capturing and updating of the text area is incredibly slow and totally burries your performance, making your realtime graphics routine fail to produce the desired timing-sensitive behavior. Therefore, either run from the command line or write to a file if starting from Eclipse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM