我正在使用 Libgdx assetmanager 加载 UI 资源。它工作得很好,直到我重新启动应用程序(Android)。 发生的情况如下:
- 我开始游戏:运行良好
- 我使用
Gdx.app.exit()
关闭应用程序(没有错误) - 现在,当我按下应用程序图标将其打开时:崩溃了!
错误:com.badlogic.gdx.utils.GdxRuntimeException:未加载资源:data/GUI/packed/gui.atlas
我尝试了finishloading()
没有运气!
我尝试使用 finishloadingasset("data/GUI/packed/gui.atlas")
这永远会阻塞!
添加了 assetmanager.dispose()
并在退出前清除。运气不好!
崩溃后,如果我尝试再次打开它,它就可以正常工作!
请多多指教! 谢谢
最佳答案
关闭 Android 中的 Activity 不会自动清除静态引用。不要保留对任何 OpenGL 相关对象(例如 AssetManagers、Textures、ShaderPrograms、SpriteBatches 等)的任何静态引用,否则您将面临 Android 重新打开游戏而不知道如何(或需要)重新加载它们的风险。
可以通过清除 Activity 的 onCreate
方法中的静态引用来解决此问题,但完全避免静态引用更安全/更容易。
关于java - Libgdx AssetManager 未在恢复时加载资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32051150/