Math SpriteKit-Zrotation与比率

Math SpriteKit-Zrotation与比率,math,clock,sprite-kit,radians,Math,Clock,Sprite Kit,Radians,我一直在尝试制作一个模拟时钟,它的时针跟在分针后面。 我尽了我所能,但比率不高 拖动分针是正确的,所以我认为这是计算时针旋转比率的方法 这是我最近尝试的许多 代码: #定义度到弧度(角度)((角度)/180.0*M#PI) #定义弧度到度(弧度)((弧度)*(180.0/M_-PI)) CGFloat oldAngleInRadians=M_PI_2; -(无效)旋转节点:(SKSpriteNode*)触碰节点:(UITouch*)触碰 { if([node isEqual:dial])返回;

我一直在尝试制作一个模拟时钟,它的时针跟在分针后面。 我尽了我所能,但比率不高

拖动分针是正确的,所以我认为这是计算时针旋转比率的方法

这是我最近尝试的许多

代码:

#定义度到弧度(角度)((角度)/180.0*M#PI)
#定义弧度到度(弧度)((弧度)*(180.0/M_-PI))
CGFloat oldAngleInRadians=M_PI_2;
-(无效)旋转节点:(SKSpriteNode*)触碰节点:(UITouch*)触碰
{
if([node isEqual:dial])返回;
CGPoint positionInDial=[触摸位置INNODE:拨号];
float deltaY=位置indial.y-分钟指示器.anchorPoint.y;
float deltaX=positionInDial.x-minuteIndicator.anchorPoint.x;
CGFloat ANGLINRADIANS=atan2f(三角洲、三角洲);
//在这种情况下,分针旋转
[节点运行动作:[SKAction rotateToAngle:angleInRadians-(M_PI/2)持续时间:0];
if(self.defficiency==kmmediumdefficiency){
[使用新角度:角度半径旧角度:角度半径旧角度]自我更新手动角度;
oldAngleInRadians=angleInRadians;
}
}
#pragma标记-用分针旋转时针
-(void)使用newAngle:(CGFloat)newAngle oldAngle:(CGFloat)oldAngle更新HourHandAngle
{
双新角度度=弧度到度(新角度);
双oldAngleDeg=弧度到度(oldAngle);
双差EG=0;
如果(新角度>0和旧角度<0){
差分deg=旧角度度-(-1*新角度度);
}否则如果(newAngleDeg<0&&oldAngleDeg>0){
差分DEG=fabsf(新角度度)-旧角度度;
}否则{
differenceDeg=新角度度-旧角度度;
}
[小时指示器运行动作:[SKAction rotateByAngle:度数到弧度((差值EG/12.0f))持续时间:0];
}

不确定我是否正确理解了您的问题,但这就是我使用SpriteKit制作模拟时钟的方法:

// MyScene.m
- (void) didMoveToView:(SKView *)view
{
    [self.clock didEnterScene];
}

- (void) update:(CFTimeInterval)currentTime
{
    CGFloat dt = 0.0;
    if (self.lastUpdateInterval > 0)
    {
        dt = currentTime - self.lastUpdateInterval;
    }
    [self.clock update:dt];
    self.lastUpdateInterval = currentTime;
}

// ClockNode.m
- (void) didEnterScene
{
    SKSpriteNode* secHand = [SKSpriteNode spriteNodeWithColor:[UIColor blueColor] size:CGSizeMake(2, 100)];
    SKSpriteNode* minHand = [SKSpriteNode spriteNodeWithColor:[UIColor greenColor] size:CGSizeMake(5, 100)];
    SKSpriteNode* hourHand = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:CGSizeMake(10, 70)];

    secHand.position = CGPointMake(CGRectGetMidX(self.scene.frame), CGRectGetMidY(self.scene.frame));
    minHand.position = secHand.position;
    hourHand.position = secHand.position;

    secHand.anchorPoint = CGPointMake(0.5, 1.0);
    minHand.anchorPoint = CGPointMake(0.5, 1.0);
    hourHand.anchorPoint = CGPointMake(0.5, 1.0);

    [self addChild:secHand];
    [self addChild:minHand];
    [self addChild:hourHand];

    _secHand = secHand;
    _minHand = minHand;
    _hourHand = hourHand;

    _secHand.zRotation = M_PI;
    _minHand.zRotation = M_PI;
    _hourHand.zRotation = M_PI;

    _msec = 0.0f;
    _sec = 0.0f;
    _min = 0.0f;
    _hour = 0.0f;
}

- (void) update:(CGFloat)dt
{
    _msec += dt;
    if (_msec >= 1)
    {
        _msec -= 1;
        _sec += 1;
        _secHand.zRotation -= 2*M_PI / 60;
    }
    if (_sec >= 60)
    {
        _sec -= 60;
        _min += 1;
        _minHand.zRotation -= 2*M_PI / 60;
    }
    if (_min >= 60)
    {
        _min -= 60;
        _hour += 1;
        _hourHand.zRotation -= 2*M_PI / 12;
    }
    if (_hour >= 12)
    {
        _hour -= 12;
    }
}

// MyScene.m
- (void) didMoveToView:(SKView *)view
{
    [self.clock didEnterScene];
}

- (void) update:(CFTimeInterval)currentTime
{
    CGFloat dt = 0.0;
    if (self.lastUpdateInterval > 0)
    {
        dt = currentTime - self.lastUpdateInterval;
    }
    [self.clock update:dt];
    self.lastUpdateInterval = currentTime;
}

// ClockNode.m
- (void) didEnterScene
{
    SKSpriteNode* secHand = [SKSpriteNode spriteNodeWithColor:[UIColor blueColor] size:CGSizeMake(2, 100)];
    SKSpriteNode* minHand = [SKSpriteNode spriteNodeWithColor:[UIColor greenColor] size:CGSizeMake(5, 100)];
    SKSpriteNode* hourHand = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:CGSizeMake(10, 70)];

    secHand.position = CGPointMake(CGRectGetMidX(self.scene.frame), CGRectGetMidY(self.scene.frame));
    minHand.position = secHand.position;
    hourHand.position = secHand.position;

    secHand.anchorPoint = CGPointMake(0.5, 1.0);
    minHand.anchorPoint = CGPointMake(0.5, 1.0);
    hourHand.anchorPoint = CGPointMake(0.5, 1.0);

    [self addChild:secHand];
    [self addChild:minHand];
    [self addChild:hourHand];

    _secHand = secHand;
    _minHand = minHand;
    _hourHand = hourHand;

    _secHand.zRotation = M_PI;
    _minHand.zRotation = M_PI;
    _hourHand.zRotation = M_PI;

    _msec = 0.0f;
    _sec = 0.0f;
    _min = 0.0f;
    _hour = 0.0f;
}

- (void) update:(CGFloat)dt
{
    _msec += dt;
    if (_msec >= 1)
    {
        _msec -= 1;
        _sec += 1;
        _secHand.zRotation -= 2*M_PI / 60;
    }
    if (_sec >= 60)
    {
        _sec -= 60;
        _min += 1;
        _minHand.zRotation -= 2*M_PI / 60;
    }
    if (_min >= 60)
    {
        _min -= 60;
        _hour += 1;
        _hourHand.zRotation -= 2*M_PI / 12;
    }
    if (_hour >= 12)
    {
        _hour -= 12;
    }
}