2012-12-13 56 views
0

我有一个比我想要绘制的大小大得多的PNG图像。我也有一个矩形,我想要PNG填充。我曾尝试这个代码,但它并没有调整PNG:WP7 C#XNA调整大小精灵

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(); 
} 

感谢

+1

你用错了。 'batch.Draw(GamePage.theImage,destinationRectangle,Color.Transparent)' - 如果使用'destinationRectangle',你的意思是“*我想把它绘制在*处”。虽然我无法想象为什么你会想要透明的颜色。 – neeKo

回答

1

让我们想象一下你的形象是250×250像素,并要填写一个300×300像素的矩形它。为此,请使用尺寸为300×300的目的地Reactangle:

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

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

代码中没有提及图像的原始大小,因为它并不重要,因为程序将使用任何给定的纹理填充目标矩形。


我和你的代码中的Color.Transparent混淆了,你真的打算画一个看不见的精灵吗?