XNA窗口错误缩放,通过调整窗口大小修复

XNA窗口错误缩放,通过调整窗口大小修复,xna,window,scale,Xna,Window,Scale,因此,我使用以下代码以任意分辨率处理渲染: int windowW = GraphicsDevice.Viewport.Width; //Save the current screen size int windowH = GraphicsDevice.Viewport.Height; RenderTarget2D screen = new RenderTarget2D(GraphicsDevice, 1024, 768, false, GraphicsDevice.DisplayMod

因此,我使用以下代码以任意分辨率处理渲染:

int windowW = GraphicsDevice.Viewport.Width; //Save the current screen size
int windowH = GraphicsDevice.Viewport.Height;
RenderTarget2D screen = new RenderTarget2D(GraphicsDevice, 1024, 768,
    false, GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24, 8, RenderTargetUsage.DiscardContents);
GraphicsDevice.SetRenderTarget(screen);
GraphicsDevice.Clear(Color.Black);

soldrGameHub.Render(gameTime, spriteBatch); //Render all to another RenderTarget

GraphicsDevice.SetRenderTarget(null);

GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();

float scaleX = windowW / 1024f; //The scales on each dimension, to keep the aspect ratio
float scaleY = windowH / 768f;
float scale;
Vector2 position; //and the position to make sure we render in the center

if (scaleX <= scaleY) { //screen taller than wide
    scale = scaleX;
    position = new Vector2(0, (windowH - 768 * scale) / 2f);
}
else {
    scale = scaleY;
    position = new Vector2((windowW - 1024 * scale) / 2f, 0);
}
soldrGameHub.SetMouseOffset((int) position.X, (int) position.Y); //Set the mouse offset
soldrGameHub.SetScale(scale); //and scale to get the right coordinates at any time.

spriteBatch.Draw(screen, position, null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0); //and finally draw the renderTarget to the screen.

spriteBatch.End();
int windowW=GraphicsDevice.Viewport.Width//保存当前屏幕大小
int windowH=GraphicsDevice.Viewport.Height;
RenderTarget2D屏幕=新的RenderTarget2D(GraphicsDevice,1024768,
false,GraphicsDevice.DisplayMode.Format,DepthFormat.Depth24,8,RenderTargetUsage.DiscardContents);
GraphicsDevice.SetRenderTarget(屏幕);
图形设备。清晰(颜色。黑色);
渲染(游戏时间,spriteBatch)//将所有对象渲染到另一个渲染目标
GraphicsDevice.SetRenderTarget(空);
图形设备。清晰(颜色。黑色);
spriteBatch.Begin();
float scaleX=windowW/1024f//每个维度上的比例,以保持纵横比
浮动刻度=窗H/768f;
浮标;
矢量2位置//以及确保渲染在中心的位置

如果(scaleX我最终启动了窗口最大化,这似乎解决了问题

如果有人真的找到了真正的解决方案,请告诉我。

可能的副本