LibGDX GwtApplication Exception (TypeError) in HTML Deployment

╄→尐↘猪︶ㄣ 提交于 2020-01-05 02:47:18

问题


I try to deploy my libgdx game in HTML. In desktop and Android it works well. When I do ./gradlew html:dist, it compile fine and I have a dist folder which is created in html folder. I succeeded to launch the game on a browser:

However, when I click on any button which will change the screen, the game crash:

The error is :

GwtApplication: exception: (TypeError) : a.g[a.b] is undefined (TypeError) : a.g[a.b] is undefined

and in the console, I have:

Error: java.lang.RuntimeException: com.google.gwt.core.client.JavaScriptException: (TypeError) : a.g[a.b] is undefined

Two questions (1, 2) have the same problem but none of these solved mine.

----- Here is how I change screen ----

When user click on Stats for exemple, my code do that:

button_stats.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y){

            stage.addAction(Actions.sequence(Actions.fadeOut(0.2f), Actions.run(new Runnable(){
                @Override
                public void run() {
                    ScreenManager.getInstance().showScreen(ScreenEnum.STATS);
                    }
            })));
        }
    });

Here is my screen manager:

public class ScreenManager {

    // Singleton: unique instance
    private static ScreenManager instance;

    // Reference to game
    private SpeedRun2Game game;

    // Singleton: private constructor
    private ScreenManager() {
        super();
    }

    // Singleton: retrieve instance
    public static ScreenManager getInstance() {
        if (instance == null) {
            instance = new ScreenManager();
        }
        return instance;
    }

    // Initialization with the game class
    public void initialize(SpeedRun2Game game) {
        this.game = game;
    }

    // Show in the game the screen which enum type is received
    public void showScreen(com.gangscred.speedrun2.screens.ScreenEnum screenEnum, Object... params) {

        // Get current screen to dispose it
        Screen currentScreen = game.getScreen();

        // Show new screen
        Screen newScreen = screenEnum.getScreen(game , params);
        game.setScreen(newScreen);

        // Dispose previous screen
        if (currentScreen != null) {
            currentScreen.dispose();
        }
    }
}

and finally my screenEnum:

public enum ScreenEnum {
STATS{
  public Screen getScreen(SpeedRun2Game game, Object... params){
      return new StatsScreen(game);
  }
}

----- EDIT -----

I added style = 'PRETTY' option as suggested to my gwt compiler, and now I have this error:

Error: java.lang.RuntimeException: com.google.gwt.core.client.JavaScriptException: (TypeError) : this$static.uniforms[this$static.currProgram] is undefined


回答1:


For some reason,in HTML you can't use static method in new Runnable. So when you want to change your screen, you need to remove the fadeout:

button_stats.addListener(new ClickListener(){
    @Override
    public void clicked(InputEvent event, float x, float y){
         ScreenManager.getInstance().showScreen(ScreenEnum.STATS);
    }
});

Or you can keep the fadeout but remove your static function and change screen directly:

SpeedRun2Game game;
...
button_stats.addListener(new ClickListener(){
    @Override
    public void clicked(InputEvent event, float x, float y){

        stage.addAction(Actions.sequence(Actions.fadeOut(0.2f), Actions.run(new Runnable(){
            @Override
            public void run() {
                game.setScreen(new StatsScreen(game));
                }
        })));
    }
});


来源:https://stackoverflow.com/questions/50835064/libgdx-gwtapplication-exception-typeerror-in-html-deployment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!