无法使用类型为 '(texture: SKTexture, color: UIColor, size: CGSize, () -> ())' 的参数列表调用 'SKSpriteNode.init'

静电冲击

谁能帮我解决这个问题?即使我使用指定的初始化程序,也会生成显示的错误。

class OtherOrb: SKSpriteNode {

override init() {

    let texture = SKTexture(imageNamed: "Orb")

    super.init(texture: texture, color: UIColor.clear, size: texture.size()){
        self.position = CGPoint(x: 0.0, y: 500.0)
        self.physicsBody = SKPhysicsBody(circleOfRadius: 20) 
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
雅各布金

您收到此错误是因为您的初始化程序后面有闭包。

在 Swift 中,编译器在方法调用之后直接将闭包解释为所述方法调用的最终参数,因此您得到的错误实际上表明不存在包含该闭包参数的初始化程序。

此外,你的代码看起来很糟糕,我不相信它是有效的 Swift。你想达到什么目的?

根据我的怀疑,我相信您的代码应该类似于以下内容:

class OtherOrb: SKSpriteNode {

    init() {

        let texture = SKTexture(imageNamed: "Orb")
        super.init(texture: texture, color: UIColor.clear, size: texture.size())

        self.position = CGPoint(x: 0.0, y: 500.0)
        self.physicsBody = SKPhysicsBody(circleOfRadius: 20)
    }

    @available(*, unavailable)
    override init(texture: SKTexture?, color: UIColor, size: CGSize) {
        super.init(texture: texture, color: color, size: size)
    }

    @available(*, unavailable)
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

也就是说,您希望一个没有参数的初始化程序作为您指定的初始化程序。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档