Rotate a Texture2D with the Draw method in XNA?

I have a problem with rotating. I know that I can rotate a Texture2D object with the draw method.

My goal is to rotate a texture by 180°. For example, if I make a picture of a human with the camera where the head is at the bottom, I want to be able to rotate it so that the head is at the top again.

Here is the code or the rotation:

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

The rotation works fine, but I have another problem:

If I add the texture to position 0,0 after rotating it, it's not visible anymore.

How do I rotate or maybe reflect the object, so that the red point will be at the top-left corner again?

Answers


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)`

Need Your Help

why canvas drawImage method is scaling?

css html5 canvas

I am trying to draw a picture on a canvas with width 150px and height 150px with the following code. However, the picture seems to be scaling with the width and height attributes I set to the canva...

writing a generic stack class in c++

c++ class templates generics inheritance

Hi i ma not sure if my code is incorrect i been searchin can find anything.