我如何暂停? [关闭]

问题描述 投票:-2回答:1

[当我尝试暂停时,游戏的屏幕只会冻结,不会暂停。

我尝试过Thread.sleep(1000);

if (Var.tropfeny > 760) {     
    Var.tropfeny = -10;      
    Var.tropfenx = Var.n1;   
    Var.playerPoints = 0;    
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

如果您对此有所了解,请帮助我。

java pause
1个回答
0
投票

使用线程。

更多信息;

https://www.geeksforgeeks.org/multithreading-in-java/https://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html

例如;

Thread t = new Thread(() -> {
    for (int i = 0; i < 5; i++) {
        System.out.println(i);
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
             e.printStackTrace();
        }
    }
});
t.start();

此后;

t.stop()将停止线程,t.notify()将继续线程。

© www.soinside.com 2019 - 2024. All rights reserved.