我试图通过在360°(右边或左边取决于点更靠近哪边)上尽可能小的路线来旋转一个精灵,让我们说它是一支枪,并且我是有几个问题。如何将一个精灵旋转到一个点?
在一个圆上,它从359°跳到0°,所以我不能直接使用我的目标角度 - 当前角度。
请记住,我正在使用SFML,因此它在isRotating为true时正在执行每个函数的功能。
这是一种提供给我的资料:
//The angle in degrees of my sprite
float currentAngle = pSprite.getRotation();
//The angle is needs to be once the rotation is over
float targetAngle = float(atan2(deltaY,deltaX) * 180/(atan(1)*4) + 180);
我使用的速度变量来递增或递减每帧的角度的值。
distance = Speed*Time.asSeconds();
currentAngle += distance;