如果在启动画面打开时中断游戏崩溃 - LIBGDX

Game crash if interrupted while Splash Screen is on - LIBGDX(如果在启动画面打开时中断游戏崩溃 - 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)