[英]Resize Win2D CanvasSwapChain for CoreWindow on XBOX One with C# (NO XAML)
我一直在为Windows 10 / Windows Phone(10)开发UWP / UWA游戏,并且一直在期待Xbox One的开发模式。 我很高兴听到今天发布的开发模式,迫不及待要回家并在我的Xbox上对其进行测试。
我的应用程序/游戏运行良好,除裁剪的绘制区域(“ titlesafe / tv safe”区域之外的外边缘)外,我还没有遇到任何错误。
我正在使用Win2D CanvasSwapChain和通用CoreWindow。
我觉得我可以使用MyCoreWindow或MyViewSource来减轻此问题,但还没有找到答案。 此时可能是睡眠不足,但我希望答案或指向它的箭头对自己和将来的求职者有很大帮助。
我宁愿不使用xaml。
这是我的查看代码。
using Windows.ApplicationModel.Core;
class MyViewSource : IFrameworkViewSource
{
public IFrameworkView CreateView()
{
return new MyCoreWindow();
}
}
这是MyCoreWindow
class MyCoreWindow : IFrameworkView
{
private IGameSurface _surface;
private Engine _gameEngine;
public void Initialize(CoreApplicationView applicationView)
{
applicationView.Activated += applicationView_Activated;
CoreApplication.Suspending += CoreApplication_Suspending;
CoreApplication.Resuming += CoreApplication_Resuming;
}
private void CoreApplication_Resuming(object sender, object e)
{
_surface.Resume(sender, e);
}
private void CoreApplication_Suspending(object sender, SuspendingEventArgs e)
{
_surface.Suspend(sender, e);
}
private void applicationView_Activated(CoreApplicationView sender, IActivatedEventArgs args)
{
Windows.UI.Core.CoreWindow.GetForCurrentThread().Activate();
}
public void Load(string entryPoint)
{
_surface.Load(entryPoint);
}
public void Run()
{
while (_gameEngine.IsRunning)
{
Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);
_surface.Update();
_surface.Draw();
}
}
public void SetWindow(Windows.UI.Core.CoreWindow window)
{
_surface = new Surface(window);
_surface.SetFrameRate(60);
_surface.SetUpdateRate(100);
_gameEngine = new Engine(_surface.CanvasDevice);
_surface.AddComponent(_gameEngine);
}
public void Uninitialize()
{
_surface.Unload();
}
public static void Main(string[] args)
{
CoreApplication.Run(new MyViewSource());
}
}
在没有XAML的情况下运行时,交换链是唯一可渲染图形的东西,因此它始终会填满整个屏幕。 若要将交换链缩放为仅适合标题安全区域,则需要将其作为输入输入到其他一些合成系统(可以是XAML或Windows.UI.Composition API),这些系统可以在填充时缩放和翻译图像在背景颜色的边界。
通过设置CanvasDrawingSession.Transform来缩放和偏移渲染,以及使用CreateLayer对其进行裁剪,可以仅绘制到Win2D交换链的选定子集。
不过,通常最好在游戏的标题安全区域以外进行绘制。 从一台电视到另一台电视,到底有多少可见空间,所以如果您将其留为黑色,则某些玩家会在游戏周围看到难看的黑色边框。 您无法在该区域绘制游戏所需的重要内容,因为其他玩家根本看不到,但是通常您会希望非必需的背景图形一直延伸到屏幕的真实边缘。
(这是开发电视显示内容的麻烦之一)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.