Rotate a 2D texture using the Draw method in XNA?

I have a rotation problem. I know that I can rotate a Texture2D object using the draw method.

My goal is to rotate the texture 180 °. For example, if I take a picture of a person with a camera where the head is below, I want it to rotate so that the head is upstairs again.

Here is the code or rotation:

spriteBatch.Draw(Texture, Position, null, Color.White, MathHelper.Pi, new Vector2(), 1.0f, SpriteEffects.None, 0f);

Rotation works fine, but I have one more problem: enter image description here

If I add a texture to position 0,0 after it rotates, it will no longer be visible.

How to rotate or flip an object so that the red dot is again in the upper left corner?

+3
source share
1 answer

http://msdn.microsoft.com/en-us/library/ff433989.aspx

public void Draw (
     Texture2D texture,
     Vector2 position,
     Nullable<Rectangle> sourceRectangle,
     Color color,
     float rotation,
     Vector2 origin,
     Vector2 scale,
     SpriteEffects effects,
     float layerDepth)

//Using:
var origin = new Vector2()
{
    X = texture.Width / 2,
    Y = texture.Height/ 2
};


spriteBatch.Draw(texture, Vector2.Zero, null, Color.White, MathHelper.Pi, origin, 1f, SpriteEffects.None, 0f)`
+3
source

All Articles