Question

Anyone here very well versed in using Android and the AndEngine game engine library?

What I am trying to do is change the screen orientation from Portrait, when on the menu screens, to Landscape when playing the game.

I currently have the game set up to use only one Android Activity and use several Scenes with a scene manager using AndEngine.

I currently can only chose one or the other regarding screen orientation. I know you can use the sensors to change the screen orientation too but I want to force the player into playing the game in Landscape and using the Menu's in Portrait.

Any ideas on how I would go about doing this?

Was it helpful?

Solution

You could try to use the build-in android function:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

While having this in your Manifest.xml:

<activity android:name=".Activity_name"
      android:configChanges="orientation">

To prevent your Game from getting restarted. You can catch those config changes with:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
       //do something
    }
    else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
       //do something        
    }
}

As described here: http://developer.android.com/guide/topics/resources/runtime-changes.html

I don't know if AndEngine will react kindly to this kind of change. The only other option in my mind would be to alter the EngineOptions which, to my knowledge, is not possible outside the onLoadEngine function.

The other obvious idea would be to just start a new Activity with a new Engine for the game itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top