在不改变方向的情况下更改SpriteKit中UIBezierPath的旋转

时间:2016-03-23 20:12:32

标签: xcode swift sprite-kit

我正在制作游戏。我想要2条单独的线顺时针旋转,当玩家触摸屏幕时,旋转应该变为逆时针。现在,当它变为逆时针时,UIBezierPath翻转节点。我不希望翻转节点,只是旋转另一种方式。

func clockwise() {
    let dx = leftside.position.x - self.frame.width / 2
    let dy = leftside.position.y - self.frame.height / 2

    let rad = atan2(dy, dx)
    let path = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 85, startAngle: rad, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)

    let follow = SKAction.followPath(path.CGPath, asOffset: false, orientToPath: true, speed: 250)

    leftside.runAction(SKAction.repeatActionForever(follow).reversedAction())

    let dx1 = rightside.position.x - self.frame.width / 2
    let dy1 = rightside.position.y - self.frame.height / 2

    let rad1 = atan2(dy1, dx1)
    let path1 = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 85, startAngle: rad1, endAngle: rad1 + CGFloat(M_PI * 4), clockwise: true)

    let follow1 = SKAction.followPath(path1.CGPath, asOffset: false, orientToPath: true, speed: 250)

    rightside.runAction(SKAction.repeatActionForever(follow1).reversedAction())       
}


func counterclockwise() {
    let dx = leftside.position.x - self.frame.width / 2
    let dy = leftside.position.y - self.frame.height / 2

    let rad = atan2(dy, dx)
    let path = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 85, startAngle: rad, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)

    let follow = SKAction.followPath(path.CGPath, asOffset: false, orientToPath: true, speed: 250)

    leftside.runAction(SKAction.repeatActionForever(follow))          
    let dx1 = rightside.position.x - self.frame.width / 2
    let dy1 = rightside.position.y - self.frame.height / 2

    let rad1 = atan2(dy1, dx1)
    let path1 = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 85, startAngle: rad1, endAngle: rad1 + CGFloat(M_PI * 4), clockwise: true)

    let follow1 = SKAction.followPath(path1.CGPath, asOffset: false, orientToPath: true, speed: 250)

    rightside.runAction(SKAction.repeatActionForever(follow1))
}

0 个答案:

没有答案