libGDX 暂停 运行 几秒钟
libGDX pause running for some seconds
我有一个应用程序,我想在其中做一个短暂的暂停。使图形 elements/changes 在两个自动交互之间更好地可见是很重要的。
我曾尝试使用上面的代码暂停 2 分钟,但它会在方法开始时导致暂停,而不是在方法内的两行代码之间。
try {
Thread.sleep(2000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
Libgdx 期望渲染循环定期 运行(大致以屏幕刷新率)并且每次都重新绘制屏幕。因此,虽然您的应用可能 "look" 已暂停,但实际上不应暂停。它应该忙于更新屏幕、更新动画、响应返回键等。
因此,您需要更明确地决定在此 window 期间阻止的内容。只是响应输入?添加新元素?那么你应该在 window.
期间跳过这些元素
long endPauseTime = 0;
当您决定要暂停时:
endPauseTime = System.currentTimeMillis() + (2 * 1000); // 2 seconds in the future
然后在你的渲染回调中:
if (endPauseTime < System.currentTimeMillis()) {
// non-paused mode, so check inputs or whatever
} else {
// paused mode, so skip some things ..
}
我有一个应用程序,我想在其中做一个短暂的暂停。使图形 elements/changes 在两个自动交互之间更好地可见是很重要的。
我曾尝试使用上面的代码暂停 2 分钟,但它会在方法开始时导致暂停,而不是在方法内的两行代码之间。
try {
Thread.sleep(2000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
Libgdx 期望渲染循环定期 运行(大致以屏幕刷新率)并且每次都重新绘制屏幕。因此,虽然您的应用可能 "look" 已暂停,但实际上不应暂停。它应该忙于更新屏幕、更新动画、响应返回键等。
因此,您需要更明确地决定在此 window 期间阻止的内容。只是响应输入?添加新元素?那么你应该在 window.
期间跳过这些元素long endPauseTime = 0;
当您决定要暂停时:
endPauseTime = System.currentTimeMillis() + (2 * 1000); // 2 seconds in the future
然后在你的渲染回调中:
if (endPauseTime < System.currentTimeMillis()) {
// non-paused mode, so check inputs or whatever
} else {
// paused mode, so skip some things ..
}