示例#1
0
  /**
   * * <b>Do NOT call this method.</b>
   *
   * <p>Called when activity is started. Initialise GameEngine objects and set options to be used by
   * the GameEngine.<br>
   * This method is part of the Android Activity lifecycle which is managed by GameEngine itself.
   *
   * @param savedInstanceState
   */
  @Override
  protected final void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    checkScreenOrientation();
    printDebugInfo("GameEngine", "oncreate....");
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED,
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);

    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    appContext = getApplicationContext();

    gameView = new GameView(this);
    mainView = new FrameLayout(this);
    mainView.addView(gameView);
    addDashboard();

    // create GameThread in one place: the startThread method

    touch = new TouchInput(gameView);
    screenButtons = new OnScreenButtons();

    GameSound.initSounds(getAppContext());

    SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    MotionSensor.initialize(sensorManager);

    screenWidth = getWindow().getWindowManager().getDefaultDisplay().getWidth();
    screenHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight();
    // default Dimensions of the game world: size of screen
    setMapDimensions(getScreenWidth(), getScreenHeight());

    setContentView(mainView);
    gameView.setKeepScreenOn(true);
  }