如何在 Xbox One 上为 UWP Monogame 绘制到整个电视屏幕?

问题描述 投票:0回答:1

我已经开始了一个游戏项目;它使用 Monogame 并打包在 UWP 应用程序中。它在 Windows 和 Xbox One 上运行良好,但 Xbox 上的视口尺寸似乎略有缩小,为 1728x972,而不是 1920x1080。我最好的猜测是它正在调整大小到标题安全区域?即使我的所有图形都适合标题安全区域,我仍然希望能够使用纯哑光颜色清除图形设备以填充整个屏幕。是否可以放大我的视口或在其外部绘制?

应用程序.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>

应用程序.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();
        }
    }
}

游戏页面.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);
        }
    }
}
uwp monogame xbox-one
1个回答
0
投票

找到答案:https://learn.microsoft.com/en-us/windows/uwp/xbox-apps/turn-off-overscan

如何将UI绘制到屏幕边缘

默认情况下,应用程序将在视口边缘放置边框以考虑 电视安全区域(有关详细信息,请参阅针对 Xbox 和 电视)。

我们建议关闭此功能并绘制到屏幕边缘。 您可以通过添加以下代码绘制到屏幕边缘 当您的应用程序启动时:

Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().SetDesiredBoundsMode(Windows.UI.ViewManagement.ApplicationViewBoundsMode.UseCoreWindow);

注:

C++/DirectX 应用程序不必担心这一点。系统总是会将你的应用程序渲染到边缘 屏幕。

© www.soinside.com 2019 - 2024. All rights reserved.