Game crash if interrupted while Splash Screen is on - LIBGDX(如果在启动画面打开时中断游戏崩溃 - LIBGDX)
问题描述
I have a splash screen and a menu screen class that loads all my texture atlases and skins for the menu and processes lots of stuff. If I put the constructor for the menu screen in the SplashScreen constructor or in the create() method of my main game class (MyGame class) then it would pass a lot of time with no splash screen render image on the phone while the whole stuff loads so I have delayed the loading of the menu class to the second frame render (gets called in the SplashScreen render method in the second frame); I simply check if I passed the first frame then I call a method on the main game class that loads the menus.
It all works fine , as expected , but only if the SplashScreen load process is not interrupted. If I get a call or I simple press the HOME button of the mobile and then I re-enter the game by clicking the icon on the home screen I get an AndroidGraphics error : "waiting for pause synchronization took too long: assuming dead lock and killing"; this is just after I can see the splash screen on the screen for about a second;
I tried to dispose the MyGame in the hide() and pause() methods of both the main game class and the splash screen class so it's terminated if I press the HOME button but they never get called.
How can I fix this? It would be annoying to get a call while loading the game and after you finish the call and try to re-enter the game it crashes.
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();
        }
        ...
    }
}
I do not understand your question very well, but if you are not using AssetManger Class, I think this read can help, I hope so.
If this response is not valid or not useful to you, tell me, and delete
wiki LibGDX https://github.com/libgdx/libgdx/wiki/Managing-your-assets
video on YouTUBE https://www.youtube.com/watch?v=JXThbQir2gU
other example in GitHub https://github.com/Matsemann/libgdx-loading-screen
NEW look this:
Proper way to dispose screens in Libgdx
What's the right place to dispose a libgdx Screen
It can help you decide if you need to call dipose, and how, I hope it will help.
这篇关于如果在启动画面打开时中断游戏崩溃 - LIBGDX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果在启动画面打开时中断游戏崩溃 - LIBGDX
				
        
 
            
        基础教程推荐
- 多个组件的复杂布局 2022-01-01
 - 验证是否调用了所有 getter 方法 2022-01-01
 - 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
 - 不推荐使用 Api 注释的描述 2022-01-01
 - 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
 - 大摇大摆的枚举 2022-01-01
 - 在 Java 中创建日期的正确方法是什么? 2022-01-01
 - Java Swing计时器未清除 2022-01-01
 - Java 实例变量在两个语句中声明和初始化 2022-01-01
 - 从 python 访问 JVM 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				