rotation - Monogame - Sprite 不围绕原点旋转

标签 rotation xna sprite monogame

我正在尝试使用以下代码绕其中心旋转 Sprite :

            Vector2 origin = new Vector2(position.Width / 2, position.Height / 2);

            s.Draw(position, origin, angle, Color.White);
            spriteBatch.Draw(texture, position, sourceRectangle, color, rotation, origin, SpriteEffects.None, 0);

注意:由于我是从 Sprite 表中绘制的,因此正在计算源矩形。

我的 Sprite 的原始大小是 15x32。如果我使用这个尺寸,旋转看起来几乎正确,但仍然有一点偏移:

enter image description here

但是,当我将宽度和高度调整为 75x128 时, Sprite 会完全移位:

enter image description here

有没有办法在调整 Sprite 大小时始终将 Sprite 放置在正确的位置?为什么在以原始尺寸绘制 Sprite 时, Sprite 甚至会发生位移?

顺便说一句,绿色框是原点,其大小是 Sprite 的大小。

非常感谢!

最佳答案

好吧,我自己想出来了!

创建原点时,我使用了新的宽度和高度 (75, 128),但必须使用原始 Sprite 的宽度和高度。在本例中为 (15, 32)。

关于rotation - Monogame - Sprite 不围绕原点旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74029630/

相关文章:

ios - 旋转时自动更新 preferredContentSize

ios - 根据设备方向切换 View

android - RelativeLayout 的旋转如何在 android 中工作?

C#/HLSL 和 XNA - 在 HLSL 中通过百分比将 2 种颜色混合在一起

c# - 我还能做些什么来提高这门课的表现?

html - 在另一个 Canvas 上绘制 Canvas 是模糊的。我该如何解决?

android - CSS3 变换 : Rotate resets on complete on Droid 2

c# - 适用于 WP7 的 XNA 高速平滑动画

php - svg 文件 phpstorm 的自动化 CSS Sprite

python - 2D 游戏中的运动(blitting 时的圆形位置?)