问题
I'm using AndEngine for a Game 2d. Wanna to load different Activities or better different Scenes for the different levels and for the main menu. How to achieve this ? ..Where can I find an example ?
回答1:
I would recommend for you to use scenes instead activities to avoid black screens between switching activities. Create your own scene manager and use it for changing screens. Basic example:
public class SceneManager {
private static Game game; // your main activity
private static SceneManager sm;
private Scene mScene;
private SceneManager(){
}
public static void init(Game pGame){
SceneManager.game = pGame;
}
public static SceneManager getManager(){
if(game == null) throw new IllegalStateException("You must first initialize scenemanager class");
if(sm == null) return sm = new SceneManager();
return sm;
}
public void setMainMenuScreen(){
mScene = new MainMenuScene();
game.getEngine().setScene(mScene);
}
public void setGameScreen(){
mScene = new GameScene();
game.getEngine().setScene(mScene);
}
public Scene getCurrScene(){
return mScene;
}
}
And in your main class Game.java firstly you should initialize your scene manager class and get local instance. After this feel free to use it according your game logic:
private SceneManager sm;
SceneManager.init(this);
sm = SceneManager.getManager();
sm.setMainMenuScreen();
...
sm.setGameScreen();
来源:https://stackoverflow.com/questions/9154251/show-different-scenes-for-different-levels-andengine