如何在曲线中移动SkspriteNode而不旋转Swift的精灵



我正在尝试用曲线移动精灵。我得到了这个代码:

let path = UIBezierPath()
path.move(to: CGPoint.zero)
path.addQuadCurve(to: CGPoint(x: ball.position.x+200, y: ball.position.y+50), controlPoint: CGPoint(x: ball.position.x+100, y: ball.position.y+200))
    ball.run(SKAction.follow(path.cgPath, speed: 1.0))

我有几个问题:1-为什么我的精灵在移动时旋转,如果我可以控制这种旋转?2-知道球为什么只移动球的一小部分,并且非常缓慢而不是平稳的移动(10-20秒)?

有人知道此代码如何工作吗?我发现的所有答案都与具有不同方法的较旧的Swift版本有关。

终于找到了解决方案:)

func beizerSprite()
   {
    // create a bezier path that defines our curve
    let path = UIBezierPath()
    path.move(to: CGPoint(x: 16,y: 239))
    path.addCurve(to:CGPoint(x: 301, y: 239),
                  controlPoint1: CGPoint(x: 136, y: 373),
                  controlPoint2: CGPoint(x: 178, y: 110))
    // use the beizer path in an action
    _playButton.run(SKAction.follow(path.cgPath,
                                    asOffset: false,
                                    orientToPath: true,
                                    speed: 50.0))
   }

此移动沿屏幕曲线中的SKSprite移动。

最新更新