简体   繁体   English

System.out.println() 破坏了我的 if 语句

[英]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.在 if 语句中添加 println 代码时,该行不再跟随鼠标。

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.您正在从 Eclipse 或类似的 IDE 运行您的程序,该 IDE 将System.out捕获到文本区域中。 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.因此,如果从 Eclipse 启动,要么从命令行运行,要么写入文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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