Closed boscharun closed 9 years ago
It seems only allow landscape.
I quite don't understand +Taug... I can set the engine options to Portrait or Landscape and both works. What I want is to detect a screen orientation change while the user is playing the game. Looks like once the scene is visible, no orientation change triggers are available.
Really?I will try later. Is the android API works for you?
Hmmm I found it.. Seems this is intentional. BaseGameActivity does
this.setRequestedOrientation(orientation);
which basically sets the orientation permanently and no onConfiguationChanged() callbacks happen. I guess AndEngine was designed like this because a game is designed based on a fixed resolution and then scaled appropriately.
For my case, I was detecting whether portrait/landscape right at the start of the game and setting the engine appropriately.
So as a workaround, modified AndEngine code (BaseGameAcitivity.java) and introducing a new "NONE" orientation which would not call setRequestedOrientation at all. In my game class, I use onConfiguationChanged() to detect orientation change and to restart the current activity so it starts again with proper orientation.
I use this function in my wallpaper code. it works good for me.
@Override
public void onSurfaceChanged(final GLState pGLState, final int pWidth, final int pHeight) {
super.onSurfaceChanged(pGLState, pWidth, pHeight);
if ( (mEngine.getEngineOptions().getScreenOrientation() == ScreenOrientation.PORTRAIT_FIXED && pWidth > pHeight) ||
(mEngine.getEngineOptions().getScreenOrientation() == ScreenOrientation.LANDSCAPE_FIXED && pHeight > pWidth)) {
mEngine.getScene().setRotation(90f);
} else {
mEngine.getScene().setRotation(0f);
}
}
Am using the latest AndEngnie with camera and Engine initialized as
Also added the following in manifest.xml
And in the game class, I have onCnfigurationChanged defined, but it never gets triggered. Is there any way I can detect Screen orientation change while the game is going on?