繁体   English   中英

WP7 C#XNA调整大小精灵

[英]WP7 C# XNA resize sprite

我的PNG图片比我要绘制的图片大得多。 我也有一个想要PNG填充的矩形。 我已经尝试过此代码,但是它不会调整PNG的大小:

public void Draw(SpriteBatch batch, float screenWidth)
{
    Rectangle destinationRectangle = new Rectangle(0, 0, 0, 0);
    destinationRectangle.Width = (int)(screenWidth / 8);
    destinationRectangle.Height = (int)(screenWidth / 8);
    Vector2 topLeft = new Vector2(0, 0);
    batch.Begin();
    batch.Draw(GamePage.theImage, topLeft, destinationRectangle, Color.Transparent);
    batch.End();
}

谢谢

假设您的图片为250×250像素,而您想用它填充300×300 px的矩形。 为此,您可以使用大小为300×300的目标Reactangle:

spriteBatch.Draw(yourImage, new Rectangle(12, 34, 300, 300), Color.White);

12和34是矩形的X和Y坐标。

在代码中没有提及图像的原始大小,因为这无关紧要,因为该程序将使用任何给定的纹理填充目标矩形。


我对您的代码中的Color.Transparent感到困惑,您真的打算绘制一个看不见的精灵吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM