how can i rotate a Texture2D in XNA game studio?
c#, xna
Solution
The texture will be rotated by 180 degree.
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);
}
As also you can flip texture vertically using 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);
}
Problem
hi i have to rotate a Texture2D, but i dont know why. its like a have a picture and i need to rotate it 180° because it's on the head and should be right. the problem is, i need to do it before i use `spriteBatch.Draw`, is this possible?