如何快速解决Libgdx中的暂停和恢复功能
我需要在 Android 版 libgdx 的暂停()和恢复()函数中编写哪些代码?
@Override
public void create() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void render() {
// TODO Auto-generated method stub
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
}
What code I need to write in the pause() and resume() functions in libgdx for Android?
@Override
public void create() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void render() {
// TODO Auto-generated method stub
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上你不需要在这两个方法中写任何东西。当您在 create() 中设置应用程序并在 render() 中绘制内容时,您的 libgdx 应用程序将运行。当另一个活动进入前台并且您返回到 libgdx 应用程序时,这甚至会起作用。
当您的 libgdx 活动因系统回收内存而终止时,情况就会发生变化。在这种情况下,您可以使用pause()来保存应用程序状态并在resume()中恢复它。 Libgdx 尚未封装 Android 的 Parcelable 概念,因此您需要找到另一种持久化机制。
Basically you do not have to write anything in those two methods. Your libgdx app will work when you setup your app in create() and draw you stuff in render(). This will even work when another activity comes into the foreground and you go back to your libgdx app.
Things change when your libgdx activity is terminated because the system reclaims memory. In that case you can use pause() to save your application state and restore it in resume(). Libgdx does not wrap the Parcelable concept of android yet so you will need to find another persistence mechanism.
可能涉及所谓上下文丢失的暂停和恢复事件。当 Android 上发生上下文丢失时,这意味着操作系统已决定强制释放已加载资源占用的内存。因此,在上下文丢失后直接访问您的资产会立即使恢复的游戏崩溃。为了防止这些崩溃,您需要在再次访问资产之前重新加载它们。
pause and resume events that might involve a so-called context loss. When a context loss occurs on Android, it means that the operating system has decided to forcefully free the memory that was occupied with your loaded assets. Therefore, directly accessing your assets after a context loss would immediately crash the resumed game. To prevent these crashes, you need to reload your assets before accessing them again.