2012-05-10 102 views
1

我有一组图像,其中每个图像需要能够旋转到90度,180度和270度。所有这些图像都是Texture2D类型。有没有为我完成这些功能?或者我应该加载每个图像的额外旋转图像?还是有更好的方法来完成这项任务?微软Xna Texture2D和旋转

回答

5

尽管您需要指定大部分(或全部)参数,但您可以使用SpriteBatch.Draw将纹理绘制到缓冲区时旋转(和缩放)纹理。角度以弧度给出。

SpriteBatch.Begin(); 
angle = (float)Math.PI/2.0f; // 90 degrees 
scale = 1.0f; 
SpriteBatch.Draw(myTexture, sourceRect, destRect, Color.White, angle, 
       position, scale, SpriteEffects.None, 0.0f); 
SpriteBatch.End(); 

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw.aspx

您也可以加载图像的预循环副本,但你可能会得到通常过早优化讲座。