I have started on a game project; it's using Monogame and packaged in a UWP app. It's running nicely on Windows and Xbox One, but the viewport size on Xbox appears to be shrunk slightly, 1728x972 instead of 1920x1080. My best guess is that it is resizing to the title safe area? Even if all my graphics do fit inside the title safe area I still want to be able to clear the graphics device with a solid matte color to fill the entire screen. Is it possible to enlarge my viewport or draw outside of it?
App.xaml
<Application
x:Class="FirstXboxGame.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Application>
App.xaml.cs
using System;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace FirstXboxGame
{
sealed partial class App : Application
{
public App()
{
this.InitializeComponent();
this.Suspending += this.OnSuspending;
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
// If window does not contain content, create a frame and navigate to the first page
if (!(Window.Current.Content is Frame rootFrame))
{
rootFrame = new Frame();
rootFrame.NavigationFailed +=
(sender, navigationFailedEventArgs) => throw new Exception("Failed to load Page " + navigationFailedEventArgs.SourcePageType.FullName);
// Place the frame in the current Window
Window.Current.Content = rootFrame;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
}
if (!e.PrelaunchActivated)
{
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(GamePage), e.Arguments);
}
Window.Current.Activate();
}
}
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}
GamePage.xaml
<Page
x:Class="FirstXboxGame.GamePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
>
<SwapChainPanel x:Name="swapChainPanel"/>
</Page>
GamePage.xaml.cs
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace FirstXboxGame
{
public sealed partial class GamePage : Page
{
readonly FirstXboxGame game;
public GamePage()
{
this.InitializeComponent();
// Create the game.
var launchArguments = string.Empty;
this.game = MonoGame.Framework.XamlGame<FirstXboxGame>.Create(launchArguments, Window.Current.CoreWindow, this.swapChainPanel);
}
}
}
FirstXboxGame.cs
using Windows.Foundation;
using Windows.Graphics.Display;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace FirstXboxGame
{
public class FirstXboxGame : Game
{
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private Size resolution;
private Rectangle screenBounds;
private Color matteColor;
public FirstXboxGame()
{
this.graphics = new GraphicsDeviceManager(this);
this.Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// Save screen info
var view = DisplayInformation.GetForCurrentView();
this.resolution = new Size(view.ScreenWidthInRawPixels, view.ScreenHeightInRawPixels);
this.screenBounds = new Rectangle(0, 0, (int) this.resolution.Width, (int) this.resolution.Height);
// Screen Colors
this.matteColor = Color.Red;
// Switch to FullScreen
if (!this.graphics.IsFullScreen)
{
this.graphics.ToggleFullScreen();
}
this.IsMouseVisible = true;
// Create the Sprite Batch
this.spriteBatch = new SpriteBatch(this.GraphicsDevice);
base.Initialize();
}
protected override void LoadContent()
{
// TODO: use this.Content to load your game content here
}
protected override void Update(GameTime gameTime)
{
var pressingBackButton = GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed;
var pressingBButton = GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed;
var pressingEscapeKey = Keyboard.GetState().IsKeyDown(Keys.Escape);
if (pressingBackButton || pressingBButton || pressingEscapeKey)
{
this.Exit();
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
// Get Viewport bounds
var isFullScreen = this.graphics.IsFullScreen;
var viewportBounds = this.GraphicsDevice.Viewport.Bounds;
var viewportTitleSafeArea = this.GraphicsDevice.Viewport.TitleSafeArea;
// Clear the viewport with matte color
this.GraphicsDevice.Clear(this.matteColor);
// Draw screen
this.spriteBatch.Begin();
// TODO: Draw Sprites
this.spriteBatch.End();
base.Draw(gameTime);
}
}
}