旋转时移动精灵节点

时间:2017-12-10 05:34:31

标签: swift sprite-kit

我正在尝试在旋转时移动Swift中的精灵节点(飞盘)。对象按预期移动,但不旋转。我将两个动作组合在一起以并行运行,但它仍然不会旋转。如果我自己运行这两个动作,它们可以工作,但不能并行。这是代码:

        //spin frisbee
        let oneRevolution = SKAction.rotate(byAngle: CGFloat.pi * 2, duration: 0.5)
        let repeatRotation = SKAction.repeatForever(oneRevolution)



        //move frisbee in an arc

        let path = UIBezierPath()
        path.move(to: CGPoint.zero)
        path.addQuadCurve(to: CGPoint(x: 3200, y: 1500), controlPoint: CGPoint(x: 50, y: 2000 ))
        let moveFrisbee = SKAction.follow(path.cgPath, duration: 1.3)


        let group = SKAction.group([repeatRotation, moveFrisbee])
        let frisbeeSequence = SKAction.sequence([frisbeeSound, group])
        frisbee.run(frisbeeSequence)

1 个答案:

答案 0 :(得分:1)

我花了大约22分钟来实现这一点,但SKAction.follow函数自动设置zRotation相对于它所遵循的路径旋转。我通过更改" let moveFrisbee"来禁用它。代码行:

let moveFrisbee = SKAction.follow(path.cgPath, asOffset: true, orientToPath: false, duration: 1.3)