2014-08-30 19 views
0

最近我向我的libgdx遊戲(libgdx版本1.3.1)添加了一個加載類。它適用於android,desktop和IOS項目。當我在調試/編譯HTML5時加載類中的無限循環(test_project available)

但是,對於HTML5,我的遊戲永遠不會運行,只會顯示黑屏。後來我發現有恆定的(如果不是無限的)下面的代碼中調用.setScreen (new Test(game))在我Loading上課的時候我調試它:


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


爲了使沒有什麼我的遊戲出錯我使用libgdx gradel工具從頭開始創建一個項目,使用gwt編譯它,並且html5項目工作正常。

然後,我剛剛在中間添加了我的Loading類,桌面效果很好,但現在html5的行爲如上所述。

任何想法?

我已上傳的測試項目 https://www.dropbox.com/s/ukvik4fcnpzl97a/test_ptoject%202.zip?dl=0

回答

1

有同樣的問題。問題

public class HtmlLauncher extends GwtApplication { 

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

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

htmlLauncher返回新ApplicationListener,所以 當你((Game) Gdx.app.getApplicationListener()) 您始終獲得新ApplicationListener,在你的屏幕

使用參考ApplecationListener

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

applicationListener.setScreen();