平滑的精灵旋转

时间:2015-03-21 18:10:14

标签: c# rotation xna sprite

我正在使用C#和XNA编写游戏。我试图顺利精灵旋转。这是我的代码:

 protected void RotateSpriteTo(int rotateTo)
    {

        if (rotateGradus > 360)
            rotateGradus = 0;

            if (rotateTo > rotateGradus)
            {
                while (rotateTo > rotateGradus)
                {
                    rotateGradus += 1;
                    rotate = (rotateGradus * (float)Math.PI) / 180;
                }
            }
             else
            {
                while (rotateTo < rotateGradus)
                    rotateGradus -=1;
                rotate = (rotateGradus * (float)Math.PI) / 180;
            }
    }

我如何称呼此方法,例如:

        if (Keyboard.GetState().IsKeyDown(Keys.A))
        {
            squarePosition.X -= speed;
            RotateSpriteTo(180);
        }

但精灵立即旋转。我该如何解决?

1 个答案:

答案 0 :(得分:0)

而不是立即旋转180度,尝试在3秒内完成此操作(也就是

RotateSpriteTo((180/3) * gameTime.ElapsedGameTime);

此外,您可能希望使用MathHelper.ToRadians而不是&#39;(float)Math.PI)/ 180&#39;。不是说它不起作用,但你可以使用内置功能,现在已经存在了。

相关问题