0
시침이 분침 뒤에 오는 아날로그 시계를 만들려고 노력 중입니다. 내가 생각할 수있는 모든 시도가 있지만 비율은 꺼져 있습니다.SpriteKit - zRotion 비율이
분침을 끌면 올바르게 작동하므로 시침이 회전해야하는 비율을 계산하는 방법이라고 생각합니다.
이 많은 내 가장 최근의 시도는 ...
코드 :
#define DEGREES_TO_RADIANS(angle) ((angle)/180.0 * M_PI)
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0/M_PI))
CGFloat oldAngleInRadians = M_PI_2;
- (void)rotateNode:(SKSpriteNode *)node forTouch:(UITouch *)touch
{
if ([node isEqual:dial]) return;
CGPoint positionInDial = [touch locationInNode:dial];
float deltaY = positionInDial.y - minuteIndicator.anchorPoint.y;
float deltaX = positionInDial.x - minuteIndicator.anchorPoint.x;
CGFloat angleInRadians = atan2f(deltaY, deltaX);
// Minute hand rotation in this case
[node runAction:[SKAction rotateToAngle:angleInRadians - (M_PI/2) duration:0]];
if (self.difficulty == kMediumDifficulty) {
[self updateHourhandAngleWithNewAngle:angleInRadians oldAngle:oldAngleInRadians];
oldAngleInRadians = angleInRadians;
}
}
#pragma mark - Rotate hour hand with minute hand
- (void)updateHourhandAngleWithNewAngle:(CGFloat)newAngle oldAngle:(CGFloat)oldAngle
{
double newAngleDeg = RADIANS_TO_DEGREES(newAngle);
double oldAngleDeg = RADIANS_TO_DEGREES(oldAngle);
double differenceDeg = 0;
if (newAngleDeg > 0 && oldAngleDeg < 0) {
differenceDeg = oldAngleDeg - (- 1 * newAngleDeg);
} else if (newAngleDeg < 0 && oldAngleDeg > 0) {
differenceDeg = fabsf(newAngleDeg) - oldAngleDeg;
} else {
differenceDeg = newAngleDeg - oldAngleDeg;
}
[hourIndicator runAction:[SKAction rotateByAngle:DEGREES_TO_RADIANS((differenceDeg/12.0f)) duration:0]];
}