我有一个启动画面和一个菜单屏幕类,它们加载我所有的纹理图集和菜单的皮肤并处理很多东西。如果我将菜单屏幕的构造函数放在 SplashScreen 构造函数 或我的主游戏类(MyGame 类)的 create() 方法中,那么它会传递很多加载所有内容时手机上没有启动画面渲染图像的时间,因此我将菜单类的加载延迟到第二帧渲染(在第二帧的 SplashScreen 渲染方法中调用);我只是检查我是否通过了第一帧,然后我在主游戏类上调用一个方法来加载菜单。
一切正常,正如预期的那样,但前提是 SplashScreen 加载过程没有中断。如果我接到一个电话,或者我只是按下手机的主屏幕按钮,然后通过单击主屏幕上的图标重新进入游戏,我会收到一个 AndroidGraphics 错误:“waiting for暂停同步时间过长:假设死锁并杀死”;这是在我能在屏幕上看到启动画面大约一秒钟之后;
我试图在主游戏类和启动画面类的 hide() 和 pause() 方法中配置 MyGame,因此如果我按下 HOME 按钮,它就会终止,但它们永远不会被调用。
我该如何解决这个问题?在加载游戏时接到电话,在您结束通话并尝试重新进入游戏后它崩溃了,这会很烦人。
public class MyGame extends Game{
...
public MainMenu menu;
...
@Override
public void create(){
this.screen_type == SCREEN_TYPE.SPLASH;
splashScreen = new SplashScreen();
setScreen(splashScreen);
}
...
@Override
public void pause(){
//never gets called if I press the HOME button in middle of splash screen
if(this.screen_type == SCREEN_TYPE.SPLASH)
{
this.dispose();
}
}
...
public void LoadMenuTimeConsumingConstructor(){
//load all menus and process data
main_menu = new MainMenu();
loaded_menu = true;
}
}
public class SplashScreen implements InputProcessor, Screen{
public MyGame main_game;
...
public SplashScreen(MyGame game){
this.main_game = game;
}
@Override
public void pause(){
//never gets called if I press the HOME button in middle of splash screen
if(main_game.screen_type == SCREEN_TYPE.SPLASH)
{
main_game.dispose();
}
}
@Override
public void hide(){
//never gets called if I press the HOME button in middle of splash screen
if(main_game.screen_type == SCREEN_TYPE.SPLASH)
{
main_game.dispose();
}
}
@Override
public void render(delta float){
...
//wait 1.5 sec
if(TimeUtils.millis() - startTime > 1500){
{
if(main_game.loaded_menu = true){
main_game.setScreen(main_game.main_menu);
}
}
...
if(is_this_second_frame){ // we start loading menus in the second frame so we already have the splash onscreen
main_game.LoadMenuTimeConsumingConstructor();
}
...
}
}
最佳答案
我不是很理解你的问题,但如果你没有使用 AssetManger 类,我认为这篇文章会有所帮助,我希望如此。
如果此回复无效或对您没有用,请告诉我,然后删除
维基 LibGDX https://github.com/libgdx/libgdx/wiki/Managing-your-assets
YouTube 上的视频 https://www.youtube.com/watch?v=JXThbQir2gU
GitHub 中的其他示例 https://github.com/Matsemann/libgdx-loading-screen
新看这个:
Proper way to dispose screens in Libgdx
What's the right place to dispose a libgdx Screen
它可以帮助您决定是否需要调用 dipose,以及如何调用,希望对您有所帮助。
关于java - 如果启动画面打开时中断,游戏会崩溃 - LIBGDX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30119243/