UWP Xbox Screen Position

Please, could someone tell me why on Xbox the Canvas is created outside of X and Y coordinates (0,0)?


Whenever I start the game, it has space at the top of the screen and on the left. Is there any way to make the Splash Screen start at (0, 0) coordinates?
This problem only occurs on Xbox.
On the PC the splash screen starts in the same position as on the Xbox, but when I go to full screen it works normally.

Reading this gave me horrific flashbacks, so I went back to an Xbox UWP build of ours and found this in my code…

At the start of Draw method:

#if XBOX
	// this jankiness is necessary for UWP for some reason or else it doesn't start in full screen or moves the window or does any number of other unfathomably stupid things
	if (!isUwpScreenSetup && IsActive)
	{
		isUwpScreenSetup = true;
		ApplyGraphicsSettings();
	}
#endif

isUwpScreenSetup is a boolean with an initial value of false just to be used as a flag so this code only runs once.

IsActive is a boolean provided by MonoGame’s Game class that is true if the application is in focus, false otherwise.

ApplyGraphicsSettings is a method that, you guessed it, applies the graphics settings. Sets the resolution/vsync/etc then calls graphics.ApplyChanges()

It’s been some years since dealing with this, so I don’t really know why it is necessary to fire this in the Draw method instead of during startup or some such, but I have to assume that Past Sam had his reasons. :stuck_out_tongue:

It didn’t work for me. I’m trying to use it like this:

In Game.cs

    protected override void Draw(GameTime gameTime)
    {
        if (!isUwpScreenSetup && IsActive)
        {
            isUwpScreenSetup = true;
            _graphics.PreferredBackBufferWidth = Globals.Size.Width;
            _graphics.PreferredBackBufferHeight = Globals.Size.Height;
            _graphics.ApplyChanges();
        }

        _gameManager.Draw(Globals.SpriteBatch);
        base.Draw(gameTime);
    }

There something missing?
Thanks.

------------------------SOLUTION!!!------------------------

After dozens of attempts, I found something that solves the problem.

In the App.xaml.cs on start of OnLaunched I put this line:
ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);

To fill the entire Core Window.

1 Like

@TheKelsam and @kyotsuyoi,

I have experienced issues with the screen position being offest over the years as well using UWP builds of MonoGame.

The fix TheKelsem laid out is needed in my UWP projects. I solved a bit differently using a timer that delayed about a second before calling ApplyGraphicsSettings. It seemed if I just waited one update cycle it wouldn’t work either. If I didn’t apply this fix it seemed the screen would be stretched incorrectly based on the actual resolution.

I’ve also experience what kyoutsuyoi had difficult with. In this case, to fix I had applied a manual nudge to move the screen into a better position on TV screens when the game is played on XBox. I’m really happy to find this fix as it is much better solution than what I was trying. Thank you for posting your solution!

One last note on this, as I investigated your fix. In a previous release of MonoGame, there used to be 2 UWP templates. The current MonoGame release uses a file called App.xaml.cs to launch Game. In this configuration, I need both the fix kyotsuyoi posted and TheKelsem posted.

In my experience, using the older style UWP template, kyotsuyoi’s fix is not needed, but TheKelsem’s still is. I don’t think anything stops someone from setting up MonoGame to run directly from Program instead of from xaml.app and I am unsure sure why one was chosen over the other in later MonoGame versions than perhaps the differences were insignificant between the two options?

So bottom line, on a current UWP MonoGame template, if someone is expreiencing problems related to resolution, I would recommend trying both a delayed setting ofApplyGraphicsSettings and also setting ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);.

I wonder if it is worth a PR to try to add kyotsuyoi’s fix to the UWP template? This post may be worth reposting over in GitHub discussions as I’m sure others will want this info if they shut down this forum.

The older UWP template would look something like below.

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
    {
        var factory = new MonoGame.Framework.GameFrameworkViewSource<Game>();
        Windows.ApplicationModel.Core.CoreApplication.Run(factory);
    }
}

Thanks again for posting, this was very helpful!

-Brett

1 Like