I have been looking into this for some time and can’t get my head around it. On certain Android devices my game gets a vertical bar of “dead” space on the right when the game is started and if I send the game to the background and re-activate it I then get an additional one on the right. I have added two GIFS to the post to help show this.
When I check GraphicsDevice.Viewport.X it is not equal to zero, I can set this back to zero, but if I put the game to the background and bring it back, the X value changes again. I can use the below code to correct it, but struggling to find where I should place it so as to avoid the need to call it every update. Similarly the width of the viewport changes at the same times.
if (GraphicsDevice != null && (GraphicsDevice.Viewport.X != 0 ||
GraphicsDevice.Viewport.Width != GraphicsDevice.Adapter.CurrentDisplayMode.Width ||
GraphicsDevice.Viewport.Width != GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width))
{
Viewport view = GraphicsDevice.Viewport;
view.X = 0;
view.Width = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
GraphicsDevice.Viewport = view;
}
I have been looking into this for some time and can’t get my head around it. On certain Android devices my game gets a vertical bar of “dead” space on the right when the game is started and if I send the game to the background and re-activate it I then get an additional one on the right. I have added two GIFS to the post to help show this.
When I check GraphicsDevice.Viewport.X it is not equal to zero, I can set this back to zero, but if I put the game to the background and bring it back, the X value changes again. I can use the below code to correct it, but struggling to find where I should place it so as to avoid the need to call it every update. Similarly the width of the viewport changes at the same times.
if (GraphicsDevice != null && (GraphicsDevice.Viewport.X != 0 ||
GraphicsDevice.Viewport.Width != GraphicsDevice.Adapter.CurrentDisplayMode.Width ||
GraphicsDevice.Viewport.Width != GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width))
{
Viewport view = GraphicsDevice.Viewport;
view.X = 0;
view.Width = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
GraphicsDevice.Viewport = view;
}
I have placed this code within the Update() method of the screen and it fixes the issue - but seems overkill to call it in every update. I have also tried to call it in overrides of the Activity and Game OnResume() & OnActivate(), it changes the viewport as required, but doesn’t hold and ends up getting set back to the values that cause the bars ‘instantly’.
Also worth noting the game is running in full screen mode.
Any advice that you can offer would be greatly appreciated.
Videos:
When Game Starts
When game resumes from background
Note: in the videos I am moving the blue marker with touch.
This is a cross post of one I placed on StackOverflow two weeks ago, when I had trouble signing up to Monogame Community.