Android Open Source - lamp-game Scene Manager






From Project

Back to project page lamp-game.

License

The source code is released under:

GNU General Public License

If you think the Android project lamp-game listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lifestudio.manager;
// w  w  w  .  j  ava2  s .  c o m
import org.andengine.engine.Engine;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.ui.IGameInterface.OnCreateSceneCallback;

import com.lifestudio.base.BaseScene;
import com.lifestudio.scene.GameScene;
import com.lifestudio.scene.LoadingScene;
import com.lifestudio.scene.MainMenuScene;
import com.lifestudio.scene.SplashScene;

public class SceneManager {

  // Scenes
  private BaseScene splashScene;
  private BaseScene menuScene;
  private BaseScene gameScene;
  private BaseScene loadingScene;

  // Variables
  public enum SceneType {
    SCENE_SPLASH, SCENE_MENU, SCENE_GAME, SCENE_LOADING,
  }

  private static final SceneManager INSTANCE = new SceneManager();

  private SceneType currentSceneType = SceneType.SCENE_SPLASH;

  private BaseScene currentScene;

  private Engine engine = ResourcesManager.getInstance().engine;

  // Class logic
  public void createMenuScene() {
    ResourcesManager.getInstance().loadMenuResources();
    menuScene = new MainMenuScene();
    loadingScene = new LoadingScene();
    SceneManager.getInstance().setScene(menuScene);
  
    splashScene.disposeScene();
  }

  public void setScene(BaseScene scene) {
    engine.setScene(scene);
    currentScene = scene;
    currentSceneType = scene.getSceneType();
  }

  public void setScene(SceneType sceneType) {
    switch (sceneType) {
    case SCENE_SPLASH:
      setScene(splashScene);
      break;
    case SCENE_MENU:
      setScene(menuScene);
      break;
    case SCENE_GAME:
      setScene(gameScene);
      break;
    case SCENE_LOADING:
      setScene(loadingScene);
      break;
    }
  }

  public static SceneManager getInstance() {
    return INSTANCE;
  }

  public SceneType getCurrentSceneType() {
    return currentSceneType;
  }

  public BaseScene getCurrentScene() {
    return currentScene;
  }

  public void createSplashScene(OnCreateSceneCallback pOnCreateSceneCallback) {
    ResourcesManager.getInstance().loadSplashScreen();
    splashScene = new SplashScene();
    currentScene = splashScene;
    pOnCreateSceneCallback.onCreateSceneFinished(splashScene);
  }

  public void loadGameScene(final Engine mEngine) {
    setScene(loadingScene);
    ResourcesManager.getInstance().unloadMenuTextures();
    mEngine.registerUpdateHandler(new TimerHandler(0.1f,
        new ITimerCallback() {
          public void onTimePassed(final TimerHandler pTimerHandler) {
            mEngine.unregisterUpdateHandler(pTimerHandler);
            ResourcesManager.getInstance().loadGameResources();
            gameScene = new GameScene();
            setScene(gameScene);
          }
        }));
  }

  // responsible for loading menu scene and displaying loading scene while
  // performing all mentioned tasks
  public void loadMenuScene(final Engine mEngine) {
    setScene(loadingScene);
    gameScene.disposeScene();
    ResourcesManager.getInstance().unloadGameTextures();
    mEngine.registerUpdateHandler(new TimerHandler(0.1f,
        new ITimerCallback() {
          public void onTimePassed(final TimerHandler pTimerHandler) {
            mEngine.unregisterUpdateHandler(pTimerHandler);
            ResourcesManager.getInstance().loadMenuTextures();
            setScene(menuScene);
          }
        }));
  }

}




Java Source Code List

com.lifestudio.GameActivity.java
com.lifestudio.base.BaseScene.java
com.lifestudio.extras.LevelCompleteWindow.java
com.lifestudio.manager.ResourcesManager.java
com.lifestudio.manager.SceneManager.java
com.lifestudio.object.Player.java
com.lifestudio.scene.GameScene.java
com.lifestudio.scene.LoadingScene.java
com.lifestudio.scene.MainMenuScene.java
com.lifestudio.scene.SplashScene.java