MonoGame / MonoGame

One framework for creating powerful cross-platform games.
http://www.monogame.net
Other
11.55k stars 2.93k forks source link

Android Orientation Problem #486

Closed DexStudio closed 12 years ago

DexStudio commented 12 years ago

I'm trying to get my game to have a locked landscape orientation, but nothing I seem to do works. Also, making it worse, when the orientation does change due to accelerometer movement, the game resets. I'm clearly doing something wrong, but I'm new to MonoGame entirely and have no idea what my wrong doings are., I'll also note I'm testing it on a live device.

Code from the beginning of my game:

public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferMultiSampling = true; graphics.IsFullScreen = true;
graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; TargetElapsedTime = TimeSpan.FromTicks(333333); }

Anyone know a way to at least lock the screen orientation?

Thanks, Hilton

tomspilman commented 12 years ago

At first glance that looks correct for XNA code... I suspect its just a bug in the Android MonoGame code.

What version of MonoGame are you using? The MonoGame 2.5 install? Are you working from the github 'develop' or 'develop3d' branch?

dellis1972 commented 12 years ago

Also what Attributes do you have on the Activity?

DexStudio commented 12 years ago

Tom: I'm using 2.5 (I just downloaded it about 2 days ago, so I assume I still have the most recent) and I believe the "develop" branch, but I honestly don't know how to tell.

Del: I know this sounds ridiculosuly rookie, but I've never worked with Android before. What do you mean by Attribute on my Activity? Are you talking about my AndroidManifest.xml code?

dellis1972 commented 12 years ago

Hi

in your main Activity (probably in Activity1.cs) you will have something like

[Activity(.... some stuff here....)] public class Activity1 : AndroidGameActivity {

if you can paste in the bit in

[Activity(

that will narrow things down a bit.

DexStudio commented 12 years ago

I have just the most basics of basics I believe:

[Activity(Label = "TouchMoveLiveDevice", MainLauncher = true, Icon = "@drawable/icon")]

That's the only one I have

dellis1972 commented 12 years ago

OK

you need to replace that with

[Activity (Label = "TouchMoveLiveDevice" , MainLauncher = true ,Icon = "@drawable/icon" ,ScreenOrientation=ScreenOrientation.Landscape ,ConfigurationChanges=ConfigChanges.Orientation|ConfigChanges.Keyboard|ConfigChanges.KeyboardHidden)]

This is why the game resets, by default on android when the orientation changes or the keyboard does, it re-created the opengl context. The ConfigurationChanges bits in the code above stops that from happening.

DexStudio commented 12 years ago

That worked flawlessly! Thank you so much.

I also want to say, cause I think you're the same person based ont he seeming identical usernames, I watched you videos on youtube for getting started with MonoGame, and they were well detailed and go me up and running on the emulator in no time. You did a great job with those.

dellis1972 commented 12 years ago

glad it worked.

glad you liked the tutorials, I need to do a new one which shows some of this stuff to do with settings up the Activity class correctly.

tomspilman commented 12 years ago

@dellis1972 - Could we add a assert in MonoGame to alert when your MonoGame SupportedOrientations doesn't match the Activity ScreenOrientation?

dellis1972 commented 12 years ago

Orientation on Android is tricky, Scott and I spend ages trying to get it working in a manner that was consistent with WP because of the numerous ways in which a user can use it.

An Assert might work, but a better idea might be to check the Attributes of the Activity at build/run time and raise an error if the ConfigurationConfig is not set (which is needs to be otherwise the gl context gets reset).

On 31 May 2012 18:20, Tom Spilman reply@reply.github.com wrote:

@dellis1972 - Could we add a assert in MonoGame to alert when your MonoGame SupportedOrientations doesn't match the Activity ScreenOrientation?


Reply to this email directly or view it on GitHub: https://github.com/mono/MonoGame/issues/486#issuecomment-6041936

KonajuGames commented 12 years ago

You should also set the desired orientation in the Activity attribute. This is also where you can prevent the activity being recreated when the orientation changes. This is not something that GraphicsDeviceManager.SupportedOrientations can change because this information is built into the activity manifest at compile time.

Add

ConfigurationChanges=ConfigChanges.Orientation|ConfigChanges.Keyboard|ConfigChanges.KeyboardHidden to the Activity attribute to prevent activity recreation on the specified changes.

Add ScreenOrientation=ScreenOrientation.Landscape to lock the activity in landscape. Note that the different releases of Android support different values for ScreenOrientation.

See http://androidapi.xamarin.com/?link=T%3aAndroid.App.ActivityAttribute for more information on the Activity attribute, and http://androidapi.xamarin.com/?link=T%3aAndroid.App.ActivityAttribute for more information on the supported screen orientation values for the different API levels.

Sly

On 1 June 2012 01:44, DexStudio < reply@reply.github.com

wrote:

I'm trying to get my game to have a locked landscape orientation, but nothing I seem to do works. Also, making it worse, when the orientation does change due to accelerometer movement, the game resets. I'm clearly doing something wrong, but I'm new to MonoGame entirely and have no idea what my wrong doings are.

Code from the beginning of my game:

public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferMultiSampling = true; graphics.IsFullScreen = true; graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;

       // Frame rate is 30 fps by default for Windows Phone.
       TargetElapsedTime = TimeSpan.FromTicks(333333);
   }

Anyone know a way to at least lock the screen orientation?

Thanks, Hilton


Reply to this email directly or view it on GitHub: https://github.com/mono/MonoGame/issues/486