调试/编译HTML5时,我的加载类中存在无限循环(可用的test_project) [英] Infinite loop in my loading class when debugging/compiling for HTML5 (test_project available)

查看:184
本文介绍了调试/编译HTML5时,我的加载类中存在无限循环(可用的test_project)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我给我的libgdx游戏(libgdx版本1.3.1)添加了一个加载类。它适用于Android,桌面和IOS项目。



但是,对于HTML5,我的游戏永远不会运行,只会显示黑屏。然后我发现在加载下面的代码中调用 .setScreen(new Test(game))是不变的(如果不是无限的) / code> class当我调试时:




  @Override 
public void render(float delta){
//清除屏幕
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

if(game.manager.update()&& timeLoading< 0){//加载一些,如果完成加载

((游戏) Gdx.app.getApplicationListener())
.setScreen(new Test(game));
//}
} else {
timeLoading- = = Gdx.graphics.getDeltaTime();
}


//显示加载屏幕
stage.act();
stage.draw();
}



<为了让我的游戏没什么问题,我使用libgdx gradel工具从头开始创建项目,使用gwt编译它,并且html5项目工作正常。



然后我在中间添加了 Loading 类,桌面效果很好,但现在html5的行为如前所述。



有什么想法?

我上传了一个测试项目
https://www.dropbox.com/s/ukvik4fcnpzl97a/test_ptoject%202.zip?dl=0

解决方案

有同样的问题。 (




$ public public GwtApplicationConfiguration getConfig() {
返回新的GwtApplicationConfiguration(640,960);
}

@Override
public ApplicationListener getApplicationListener(){
return new ApplicationListener();




$ b

htmlLauncher return new ApplicationListener ,所以
当你((Game)Gdx.app.getApplicationListener())
时,你总是得到新的 ApplicationListener



在屏幕中使用对 ApplecationListener
$ $ $ $ $ $ $ this.applicationListener = applicationListener;
}

applicationListener.setScreen();


Recently I added a loading class to my libgdx games (libgdx version 1.3.1). It works fine for the projects android, desktop and IOS.

However, for HTML5 my game never runs and only shows a black screen. Then I found out there is constant(if not infinite) call to .setScreen (new Test(game)) in the code below in my Loading class when I debug it:


   @Override
public void render(float delta) {
    // Clear the screen
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    if (game.manager.update() && timeLoading < 0) { // Load some, will return true if done loading

            ((Game) Gdx.app.getApplicationListener())
            .setScreen(new Test(game)); 
        //}
    }else{
        timeLoading-=Gdx.graphics.getDeltaTime();
    }


    // Show the loading screen
    stage.act();
    stage.draw();
}


To make there is nothing wrong with my game I create a project from the scratch using the libgdx gradel tool, compile it using the gwt and the html5 project worked fine.

Then I just added my Loading class in the middle, the desktop works great, but the html5 now behaves as I mentioned above.

Any ideas?

I have uploaded a test project https://www.dropbox.com/s/ukvik4fcnpzl97a/test_ptoject%202.zip?dl=0

解决方案

Have the same problem. issue

 public class HtmlLauncher extends GwtApplication {

        @Override
        public GwtApplicationConfiguration getConfig () {
                return new GwtApplicationConfiguration(640, 960);
        }

        @Override
        public ApplicationListener getApplicationListener () {
                return new ApplicationListener ();
        }
    }

htmlLauncher return new ApplicationListener,so when you ((Game) Gdx.app.getApplicationListener()) your always get new ApplicationListener,

use in your screen a reference to ApplecationListener

public MainMenuScreen(ApplicationListener  applicationListener ) 
{
    this.applicationListener=applicationListener ;
}

applicationListener.setScreen();

这篇关于调试/编译HTML5时,我的加载类中存在无限循环(可用的test_project)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆