C# 在全屏模式下使对象停在屏幕边缘

C# 在全屏模式下使对象停在屏幕边缘,c#,xna,C#,Xna,最近,我通过添加graphics.IsFullScreen=true,将游戏升级为全屏设置,但这似乎给我带来了一些移动边界的错误 这就是我到目前为止得到的,其中bounds是一个矩形,location是一个向量2: if (bounds.Top > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - 10) { location.Y = GraphicsAdapter.DefaultAdapter.CurrentDi

最近,我通过添加
graphics.IsFullScreen=true,将游戏升级为全屏设置,但这似乎给我带来了一些移动边界的错误

这就是我到目前为止得到的,其中
bounds
是一个矩形,
location
是一个向量2:

if (bounds.Top > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - 10)
{
    location.Y = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - 10;
}

if (bounds.Bottom < GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height + 10)
{
    location.Y = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height + 10 + bounds.Height;
}

if (bounds.Left < GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - 10)
{
    location.X = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - 10;
}

if (bounds.Right > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width + 10)
{
    location.X = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width + 10 + bounds.Width;
}
if(bounds.Top>GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height-10)
{
location.Y=GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height-10;
}
if(bounds.BottomGraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width-GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width+10)
{
location.X=GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width-GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width+10+bounds.Width;
}

出于某种原因,这似乎不起作用,我的对象似乎完全从屏幕上消失了。哦,-10px/+10px只是一个1o像素的边框,我想在整个屏幕上显示!有什么想法吗?

不要使用GraphicsAdapter.DefaultAdapter.CurrentDisplayMode获取宽度和高度。即使您的显示器和Pc可能正在运行1920x1080,当您全屏显示XNA游戏窗口时,它也会将显示器重新缩放到游戏运行时的任何分辨率。例如1280x800或其他任何东西。@BjarkeSøgaard那么我应该用什么呢?我已经从你的问题标题中删除了标签,这取决于你的标准解决方案是什么。如果您没有更改它,我认为它是800x600或1024x768。