参数标签不匹配任何可用的重载 [sprite.physicsBody?.vector = CGVector()]

Argument labels do not match any available overloads [sprite.physicsBody?.vector = CGVector()]

好的。我正在尝试使用我自己的 sprite 来编写 Flappy Bird 的演绎版来获得乐趣和学习。我一直在实施物理学,现在正在尝试对某些物理物体施加脉冲并定义速度。我知道物理原理是有效的,因为我的幽灵精灵掉到了地上,但是我在为幽灵精灵实现速度和脉冲时遇到了一些问题(让它跳起来又掉下来)。

这是我的代码:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    Ghost.physicsBody?.velocity = CGVector(0, 0)
    Ghost.physicsBody?.applyImpulse(CGVector(0, 90))

}

我在使用 CGVector 的两行中收到错误。我相信在 swift 的早期版本中,这是 CGVectorMake。错误如下:

Argument labels '(_, _)' do not match any available overloads

我真的不确定这意味着什么或如何解决这个问题。如有必要,我可以 link 更多代码,但它相当冗长。我感谢任何建议或提示。这是使用迄今为止最新的 swift 和 Xcode。 Xcode 9.0 和 Swift 4.0.3.

您的 CGVector init 缺少参数标签。您可以通过更改为

来修复
CGVector(dx: 0, dy: 90)

作为参考,查看苹果文档以了解这些类型的错误:https://developer.apple.com/documentation/coregraphics/cgvector

查看 the documentation for CGVector,我看到以下形式的构造函数:

init(dx: Double, dy: Double)

这意味着您需要输入 CGVector(dx: 0, dy: 0).

而不是输入 CGVector(0, 0)

为了将来参考,当您看到下划线标签时,它通常表示 "no label" — 您将查找您传递的没有前面名称的参数值,并添加一个 API 预计。