您始终可以创建自己的缩放实现。
例如,默认的目标视口尺寸为:
const int defaultWidth = 1280, defaultHeight = 720;
你当前的屏幕尺寸是800×600,这给了你一个(让我们使用Vector2而不是两个浮点数):
int currentWidth = GraphicsDevice.Viewport.Width,
currentHeight = GraphicsDevice.Viewport.Height;
Vector2 scale = new Vector2(currentWidth / defaultWidth,
currentHeight / defaultHeight);
这会给你一个{0.625; 0.83333}。您现在可以在一个方便的 SpriteBatch.Draw() overload 中使用它,它需要一个 Vector2 缩放变量:
public void Draw (
Texture2D texture,
Vector2 position,
Nullable<Rectangle> sourceRectangle,
Color color,
float rotation,
Vector2 origin,
Vector2 scale,
SpriteEffects effects,
float layerDepth
)
或者,您可以将所有内容绘制到 RenderTarget2D 并将生成的图像从那里复制到主屏幕上的拉伸纹理,但这仍然需要上述 SpriteBatch.Draw() 重载,尽管它可能会节省您的时间如果你有很多draw call。