C# directx 精灵起源
当我的 Sprite 旋转原点固定在窗口的左上角时,我遇到这个问题(与 sprite.Draw 和 sprite.Draw2D 相同) 不管怎样,如果我改变旋转中心,它仍然在左上角。我需要精灵绕其 Z 轴旋转。
编辑: 我已经尝试过这个:
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);
但它似乎效果不佳......
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 if i change rotation center it's still at top left. I need sprite to rotate around its Z axis.
Edit:
I have tried this:
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);
But it does not seem to works well...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当你画它的时候,它在正确的位置吗?
我相信乘法顺序是相反的,并且您不应该根据变换中玩家的位置进行变换。
编辑
您还可以使用
Matrix.Transformation
方法一步获得矩阵。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.
Edit
You could also use the
Matrix.Transformation
method to get the matrix in one step.我已经为您找到了解决方案,这是一个简单的方法,您可以在每次想要绘制精灵时使用。
通过这种方法,您将能够以所需的旋转中心旋转精灵。
I've got the solution for you, it's a simple method that you can use everytime you want to draw a sprite.
With this method you will be able to rotate the sprite with your desired rotation center.