HTML部署中的LibGDX GwtApplication异常(TypeError) [英] LibGDX GwtApplication Exception (TypeError) in HTML Deployment

查看:304
本文介绍了HTML部署中的LibGDX GwtApplication异常(TypeError)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用HTML部署我的libgdx游戏。在桌面和Android中它运行良好。当我做 ./ gradlew html:dist 时,它编译得很好,我有一个在html文件夹中创建的dist文件夹。我成功地在浏览器上启动游戏:

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:

错误是:


GwtApplication:exception:(TypeError):ag [ab]未定义
(TypeError):ag [ab]未定义

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

在控制台中,我有:


错误:java .lang.RuntimeException:com.google.gwt.core.client.JavaScriptException:(TypeError):ag [ab] is undefined

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

两个问题( 1 2 )有同样的问题,但这些都没有解决我的问题。

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

----- 这是我改变屏幕的方式 ----

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

当用户点击Stats例如,我的代码会这样做:

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);
                    }
            })));
        }
    });

这是我的屏幕管理员:

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();
        }
    }
}

最后我的screenEnum:

and finally my screenEnum:

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

----- 编辑 -----

----- EDIT -----

我根据建议添加了style ='PRETTY'选项给我的gwt编译器,现在我有这个错误:

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


错误:java.lang.RuntimeException:com.google.gwt.core.client.JavaScriptException:(TypeError):this $ static.uniforms [this $ static。 currProgram]未定义

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


推荐答案

出于某种原因,在HTML中你不能使用静态方法在新的Runnable中。因此,当您想要更改屏幕时,需要删除淡出:

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));
                }
        })));
    }
});

这篇关于HTML部署中的LibGDX GwtApplication异常(TypeError)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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