首页 文章

使用XNA中的Draw方法旋转Texture2D?

提问于
浏览
3

我有旋转问题 . 我知道我可以使用draw方法旋转Texture2D对象 .

我的目标是将纹理旋转180° . 例如,如果我使用头部位于底部的相机拍摄人物照片,我希望能够旋转它以使头部再次位于顶部 .

这是代码或轮换:

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

旋转工作正常,但我有另一个问题:
enter image description here

如果我在旋转后将纹理添加到位置0,0,它就不再可见了 .

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

1 回答

  • 3

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

相关问题