我正在尝试旋转Texture2D
以正确适合/填充旋转Polygon
(我自己的类)的边界,但它拒绝正常工作。SpriteBatch
我使用的方法是:
spriteBatch.Draw(texture, new Rectangle((int)Position.X, (int)Position.Y, Width, Height), null, color, Rotation, Vector2.Zero, SpriteEffects.None, 1.0f);
但是,其中唯一重要的位是Rectangle
和 origin,当前设置为Vector2.Zero
。运行上面的代码时,它会生成此图像,其中Texture2D
(填充的红色方块)与Polygon
(石灰线框)的偏移值为(texture.Width / 2, texture.Height / 2)
. 但是,旋转是正确的,因为两种形状都有平行边。
我努力了:
spriteBatch.Draw(texture, new Rectangle((int)Position.X, (int)Position.Y, Width, Height), null, color, Rotation, new Vector2(Width / 2, Height / 2), SpriteEffects.None, 1.0f);
此调用的唯一区别是我将原点(Texture2D
应围绕其旋转的点)更改为new Vector2(Width / 2, Height / 2)
,这导致此图像中 与Texture2D
的偏移Polygon
值为(-Width, -Height)
,但它仍随 旋转Polygon
。
发生的另一个错误是,当使用Texture2D
与第一个不同的宽度和高度时——尽管它应该产生相同的结果,因为destinationRectangle
字段没有改变——但它在程序中是不同的,如此图所示。同样,这使用与之前完全相同的调用,只是使用不同的图像(具有不同的尺寸)。
对这些问题中的任何一个的任何帮助将不胜感激。谢谢!
胡子哥哥
繁花如伊
皈依舞
相关分类