Hello, for my first time I execute a Monogame Android project on my phone, it was just suppose to display a grass square block at the top left corner.
So first I try with this scripts : screenshot n°5 ( note, I wrote the number of the screenshot myself with a software ), and I get this result : screenshot n°1 . It a little weird because the unused space between the top screen and the texture correspond to the barre notification. If it turn my device, I got the screenshot n°2, and if I turn it again, I got the screenshot n°3 .
I also try this program : screenshot n°6 ( not very optimized I know ), and I get the screenshot n°1, If it turn my device, I got the screenshot n°2, and if I turn it again, I got the screenshot n°4.
I want to know how I can “remove” the unused space between the top screen and the texture, I don’t want turn twice my device each time to have the good display, and also how I can detect when the user turn his device
but the result is the same as my first try in my first post (screenshot n°1,2,3)
Note, I also try do to it in an emulator, same result, except this I don’t get the “unused space”.
I also try with GraphicsDevice.Viewport.Width/Height instead of Window.ClientBounds.X/Y, same result again ( with the unused space).
this time, the project is well initialize, I get the screenshot n°4 ( it’s okay), if I flip my device I get the screenshot n°2 ( it’s okay again ) , and if I flip it again I get …the screenshot n°1 ( the wrong case ).
I can patch it by doing an “graphics.ApplyChanges();” each time in the Update method, but that will no be otpimised…
Do there is a way to detect when the user flip his device ?
This is the problem. The backbuffer should under normal circumstances always be the same size as the window/screen.
Just check Window.ClientBounds.<Width/Height> on each frame. Or check GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.<Width/Height> which should be the whole display… This might work for fullscreen devices such as Android, but for windowed devices like Pc & Mac you need the check the window.
Adding X&Y to the size of the backbuffer is not a good idea! This defines the location of the window on the screen and should not be added to the dimensions.
I had similar issues on my Android version. I used the ClientSizeChanged event on the Game class. When this event occurs, I pass the info along to my screen manager, which then sets it the usual MonoGame way (as you have above).
One other thing of note, for Android, they have this system UI thing that takes up a portion of your resolution. You can hide it and set a full screen mode. I put it in a method and call it from my AndroidGameActivity.OnResume method.
private void HideSystemUI()
{
// Apparently for Android OS Kitkat and higher, you can set a full screen mode. Why this isn't on by default, or some kind
// of simple switch, is beyond me.
// Got this from the following forum post: http://community.monogame.net/t/blocking-the-menu-bar-from-appearing/1021/2
if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
View decorView = Window.DecorView;
var uiOptions = (int)decorView.SystemUiVisibility;
var newUiOptions = (int)uiOptions;
newUiOptions |= (int)SystemUiFlags.LowProfile;
newUiOptions |= (int)SystemUiFlags.Fullscreen;
newUiOptions |= (int)SystemUiFlags.HideNavigation;
newUiOptions |= (int)SystemUiFlags.ImmersiveSticky;
decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;
this.Immersive = true;
}
}
This is only Android though… I haven’t gotten into iOS yet. You can thank Apple for that… it’s silly that they require an Apple computer on the network to build. My iPhone apparently isn’t enough >.<