现在我的代码旋转 _eye 以查看 _me 但当 _eye 从 359 度旋转到 1 度时,它不会通过 359 -> 0 -> 1 旋转,而是 359 -> 358 -> .. -> 2 -> 1。
#define SK_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f)
#define SK_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches)
{
CGPoint location = [touch locationInNode:self];
[_me runAction:[SKAction moveTo:location duration:0.5]];
}
}
-(void)update:(CFTimeInterval)currentTime
{
float deltaX = _me.position.x - _eye.position.x;
float deltaY = _me.position.y - _eye.position.y;
float angle = atan2f(deltaY, deltaX);
[_eye runAction:[SKAction rotateToAngle:angle - SK_DEGREES_TO_RADIANS(90.0f) duration:0.2]];
}
最佳答案
要将 Sprite 旋转最小角度,请将 shortestUnitArc 添加到 SKAction 中:
[_eye runAction:[SKAction rotateToAngle:angle - SK_DEGREES_TO_RADIANS(90.0f) duration:0.2 shortestUnitArc:YES]];
来自 Apple 的文档,
shortestUnitArc
If YES, then the rotation is performed in whichever direction results in the smallest rotation. If NO, then the rotation is interpolated.
关于ios - 使用最短角度旋转 Sprite 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25796751/