当我的精灵旋转原点固定在窗口的左上角时(与精灵绘制 and 精灵.Draw2D)
不管怎样,如果我改变旋转中心,它仍然在左上角。我需要精灵绕其 Z 轴旋转。
Edit:我已经尝试过这个:
hereMatrix pm = Matrix.Translation(_playerPos.X + 8, _playerPos.Y + 8, 0);
sprite.Transform = Matrix.RotationZ(_angle) * pm;
sprite.Draw(playerTexture, textureSize, new Vector3(8, 8, 0), new Vector3(_playerPos.X, _playerPos.Y, 0), Color.White);
但效果似乎不太好...
当你画它的时候,它在正确的位置吗?
我相信乘法顺序是相反的,并且您不应该根据变换中玩家的位置进行变换。
// 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
您还可以使用Matrix.Transformation
一步求出矩阵的方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)