您可以隨時創建自己的縮放實現。
例如,默認的目標視窗尺寸爲:
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()
超載,但如果您有大量繪製調用,它可能會節省您的時間。
什麼尺寸的精靈比例尺與哪個視口有多大?一個例子會很棒。 – user1306322