我有一个 plass屏幕和菜单屏幕class ,它为菜单加载我的所有纹理地图和皮肤,并处理很多东西。如果我将菜单屏幕的构造函数放在 splashscreen constructor 或 create()我的主游戏类(mygame类)的方法中,那么它将通过很多。当整个内容加载时,没有飞溅屏幕在手机上渲染图像的时间,因此我将菜单类的加载延迟到第二帧渲染(在第二帧中以plashscreen渲染方法进行调用);我只是检查是否通过了第一帧,然后在主游戏类中调用加载菜单的方法。
正如预期的那样,这一切都很好,但是只有在没有中断启动屏幕载荷过程中。如果我接到电话或简单地按"手机的主页"按钮,然后通过单击主屏幕上的图标来重新输入游戏暂停同步花费了太长时间:假设死锁和杀死" ;这是在我可以在屏幕上看到飞溅屏幕大约一秒钟之后;
我试图将Mygame放在主游戏类和Splash屏幕类的hide()和pape()方法中,因此,如果我按"主"按钮,它将终止,但它们从未被调用。
我该如何解决?加载游戏时接到电话会很烦人
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类,我认为这读可以有所帮助,我希望如此。
如果此响应对您无效或无用,请告诉我,并删除
wiki libgdxhttps://github.com/libgdx/libgdx/wiki/managing-your-assets
YouTube上的视频https://www.youtube.com/watch?v=jxthbqir2gu
github中的其他示例https://github.com/matsemann/libgdx-loading-screen
new 看此事:
在libgdx中处置屏幕的正确方法
处置libgdx屏幕的正确位置
它可以帮助您确定是否需要致电二倍,我希望它会有所帮助。