问题
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
回答1:
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();
来源:https://stackoverflow.com/questions/25582870/infinite-loop-in-my-loading-class-when-debugging-compiling-for-html5-test-proje