C# directx sprite origin

前端 未结 2 1184
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-22 01:05

i have this problem when my Sprite rotation origin is fixed at top left corner of window (same with sprite.Draw and sprite.Draw2D) Either way i

2条回答
  •  北海茫月
    2021-01-22 01:51

    When you draw it, is it in the correct place?

    I believe that the multiplication order is reversed, and that you shouldn't be transforming by the players position in the transform.

    // shift centre to (0,0)
    sprite.Transform = Matrix.Translation(-textureSize.Width / 2, -textureSize.Height / 2, 0);
    
    // rotate about (0,0)
    sprite.Transform *= Matrix.RotationZ(_angle); 
    
    
    sprite.Draw(playerTexture, textureSize, Vector3.Zero,
                new Vector3(_playerPos.X, _playerPos.Y, 0), Color.White);
    

    Edit

    You could also use the Matrix.Transformation method to get the matrix in one step.

提交回复
热议问题