2012-04-11 55 views
0

我一直試圖讓我的應用程序從一個場景更改爲另一個。我所做的是onLoadScene()我將它引導到一個有場景的方法,而我試圖做的是設置另一個場景的另一種方法......但是我得到的是第一個場景中的精靈卡住了屏幕 !在AndEngine mEngine.setScene()函數不工作

有人可以幫助我教我如何在同一個班級中從一個場景轉換到另一個場景。

這裏是我的代碼:

@Override 
public Scene onLoadScene() { 
    return splashGame(); 
} 

private Scene splashGame(){ 
    final Scene sceneGameSplash = new Scene(); 

    sceneGameSplash.setBackgroundEnabled(false); 

    System.out.println("pls work 1"); 
    final Sprite splashSprite = new Sprite(0,0, this.gameSplashScreenRegion); 

    sceneGameSplash.registerUpdateHandler(new TimerHandler(3f, true, new ITimerCallback() { 
      @Override 
      public void onTimePassed(final TimerHandler pTimerHandler) { 
      sceneGameSplash.unregisterUpdateHandler(pTimerHandler); 

      System.out.println("pls work"); 


      splashUnjum(); 
      } 
    })); 

    splashSprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 
    splashSprite.setHeight(display.getHeight()); 
    splashSprite.setWidth(display.getWidth()); 

    sceneGameSplash.attachChild(splashSprite); 


    return sceneGameSplash; 

} 

private Scene splashUnjum(){ 

    final Scene sceneUnjumSplash = new Scene(); 
    this.mEngine.setScene(sceneUnjumSplash); 

    System.out.println("pls work 2"); 
    final Sprite splashUnjumSprite = new Sprite(0,0,this.gamevedaSplashScreenRegion); 
    splashUnjumbleSprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 
    splashUnjumSprite.setHeight(display.getHeight()); 
    splashUnjumSprite.setWidth(display.getWidth()); 

    sceneUnjumSplash.attachChild(splashUnjumSprite); 

    sceneUnjumSplash.registerUpdateHandler(new TimerHandler(3f, true, new ITimerCallback() { 
     @Override 
     public void onTimePassed(final TimerHandler pTimerHandler) { 
      sceneUnjumSplash.unregisterUpdateHandler(pTimerHandler); 

      System.out.println("pls work yo"); 

      mainMenu(); 
     } 
    })); 


    return sceneUnjumSplash; 

} 

回答

1

我不知道這是問題,但我認爲你應該刪除從splashUnjum()

this.mEngine.setScene(sceneUnjumSplash); 

此行更換呼叫splashUnjum ()與

this.mEngine.setScene(splashUnjum()); 

你應該做的另一件事是確保更改發生在updateThread