游戏崩溃,如果中断,同时启动屏幕上 - LIBGDX屏幕上、游戏、LIBGDX

2023-09-12 05:04:03 作者:我依然骄纵

我有我的加载所有的纹理地图和外观的菜单和处理很多琐碎的事情一个开机画面和菜单界面类。如果我把构造菜单画面在闪屏构造或创建()我的主要的游戏类(MyGame类)的方法,那么它会通过很多时间不闪屏呈现的图像在手机上,同时在整个负载的东西,所以我推迟了菜单类加载到第二帧渲染(被称为在闪屏在第二帧渲染方法);我只是检查,如果我通过了第一帧,然后我呼吁加载菜单主要的游戏类中的方法。

这一切工作正常,符合市场预期,但前提是闪屏加载过程不会中断。如果我接到一个电话,或我简单的preSS移动,然后我重新进入游戏的HOME按钮,通过点击主屏幕上的图标,我碰到一个 AndroidGraphics 错误: 等待同步暂停时间过长:假设死锁和杀害;这只是后,我可以在屏幕上看到的闪屏约1秒钟;

我试图处置MyGame在隐藏()和pause()这两个主要的游戏类和闪屏类,所以它的终止,如果我preSS的HOME按钮,但他们从来没有被调用的方法。

我该如何解决这个问题?这将是烦人接到一个电话,而游戏加载完成后完成呼叫,并尝试重新进入它崩溃的比赛。

 公共类MyGame扩展游戏{
    ...
    公共MainMenu的菜单;
    ...
    @覆盖
    公共无效创建(){
        this.screen_type == SCREEN_TYPE.SPLASH;
        闪屏=新闪屏();
        setScreen(闪屏);
    }
    ...
    @覆盖
    公共无效暂停(){
        //不会被调用,如果我美元的启动画面中间p $ PSS HOME键
        如果(this.screen_type == SCREEN_TYPE.SPLASH)
        {
            this.dispose();
        }
    }
    ...
    公共无效LoadMenuTimeConsumingConstructor(){
        //加载所有的菜单和处理数据
        MAIN_MENU =新的MainMenu();
        loaded_menu = TRUE;
    }
}

公共类闪屏实现InputProcessor,屏幕{

    公共MyGame main_game;
    ...
    公共闪屏(MyGame游戏){
        this.main_game =游戏;
    }

    @覆盖
    公共无效暂停(){
        //不会被调用,如果我美元的启动画面中间p $ PSS HOME键
        如果(main_game.screen_type == SCREEN_TYPE.SPLASH)
        {
            main_game.dispose();
        }
    }

    @覆盖
    公共无效隐藏(){
        //不会被调用,如果我美元的启动画面中间p $ PSS HOME键
        如果(main_game.screen_type == SCREEN_TYPE.SPLASH)
        {
            main_game.dispose();
        }
    }

    @覆盖
    公共无效渲染(增量浮动){
        ...

        //等待1.5秒
        如果(TimeUtils.millis() -  startTime时> 1500){
        {
            如果(main_game.loaded_menu =真){
                main_game.setScreen(main_game.main_menu);
            }

        }

        ...

        如果(is_this_second_frame){//我们开始加载菜单在第二帧,所以我们已经有了飞溅屏幕
            main_game.LoadMenuTimeConsumingConstructor();
        }

        ...
    }
}
 

解决方案

我不明白你的问题非常好,但如果你不使用AssetManger类,我觉得这个读可以帮助,我希望如此。

如果这种反应是无效或对你有用,告诉我,并删除

维基LibGDX https://github.com/libgdx/libgdx/wiki/Managing-your-assets

YouTube上的视频 https://www.youtube.com/watch?v=JXThbQir2gU

libgdx 3d 使用Java和libgdx进行3D游戏编程,使用Blender建立模型

在GitHub的其他例子 https://github.com/Matsemann/libgdx-loading-screen

新看看这个:

有道处置在Libgdx屏幕

What's正确的地方配置一个libgdx屏幕

它可以帮助你决定​​是否需要调用dipose,怎么样,我希望这将有助于。

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.