如果在Splash Screen打开时中断游戏崩溃 - LIBGDX

gog*_*pel 5 java libgdx android-activity scene2d

我有一个启动画面和一个菜单屏幕类,它为菜单加载我所有的纹理图册和皮肤并处理很多东西.如果我把菜单屏幕的构造函数放在SplashScreen构造函数或我的主游戏类(MyGame类)的create()方法中,那么它会在手机上传递很多时间而没有闪屏渲染图像,而整个东西加载所以我已经将菜单类的加载延迟到第二帧渲染(在第二帧中的SplashScreen渲染方法中调用); 我只是检查是否通过了第一帧,然后在主游戏类上调用加载菜单的方法.

一切正常,正如预期的那样,但前提是SplashScreen加载过程没有中断.如果我接到电话或者我只需按下移动设备的HOME按钮然后我通过单击主屏幕上的图标重新进入游戏我得到一个AndroidGraphics错误:"等待暂停同步花了太长时间:假设死锁和杀死" ; 这是在我看到屏幕上的闪屏大约一秒之后;

我试图在主游戏类和启动画面类的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();
        }

        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

Ang*_*gel 2

我不太明白你的问题,但如果你没有使用 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

新的外观是这样的:

在 Libgdx 中处理屏幕的正确方法

放置 libgdx Screen 的正确位置在哪里

它可以帮助您决定是否需要调用 dipose,以及如何调用,希望对您有所帮助。