2012-04-10 70 views
3

您好我必须旋转一个Texture2D,但我不知道为什么。 它像一个有图片,我需要旋转180°,因为它在头上,应该是正确的。如何在XNA游戏工作室中旋转Texture2D?

问题是,我需要这样做之前我使用spriteBatch.Draw,这可能吗?

回答

3

纹理将被旋转180度。

protected override void Draw(GameTime gameTime) 
    { 
     spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None, RasterizerState.CullCounterClockwise, null); 
     spriteBatch.Draw(texture, Position, null, Color.White, (float)Math.PI, new Vector2(texture.Width, texture.Height), 1, SpriteEffects.None, 0); 
     spriteBatch.End(); 
     base.Draw(gameTime); 
    } 

正如你也可以使用SpriteEffects垂直翻转质地:

protected override void Draw(GameTime gameTime) 
    { 
     GraphicsDevice.Clear(Color.CornflowerBlue); 
     spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None, RasterizerState.CullCounterClockwise, null); 
     spriteBatch.Draw(texture, Position, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.FlipVertically, 0); 
     spriteBatch.End(); 
     base.Draw(gameTime); 
    } 
+0

这翻转是我需要的! – gurehbgui 2012-04-13 06:22:54

3

Draw方法有一个overload,它可以让你旋转纹理。我不确定我是否明白为什么在绘制之前需要旋转纹理。缩放和旋转通常在绘制过程中完成。正如Joel所指出的那样,旋转是使用弧度完成的,而且您还需要关注起点,这是您旋转的点。

+3

+1请注意,角弧度不度。所以180度是PI。这是一张图。 http://math.rice.edu/~pcmi/sphere/degrad.gif – Joel 2012-04-10 16:19:44

+0

@Joel:没错。感谢提及。 – 2012-04-10 16:31:25