现在我的代码旋转了_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]];
}
答案 0 :(得分:2)
要以最小的角度旋转精灵,请将shortestUnitArc添加到SKAction:
[_eye runAction:[SKAction rotateToAngle:angle - SK_DEGREES_TO_RADIANS(90.0f) duration:0.2 shortestUnitArc:YES]];
从Apple的文档中
shortestUnitArc
如果是,则以任何方式执行旋转 方向导致最小的旋转。如果否,则旋转 是插值的。