【问题标题】:swift cgsize error Argument labels '(_:, _:)' do not match any available overloadsswift cgsize错误参数标签'(_:,_:)'不匹配任何可用的重载
【发布时间】:2018-09-02 19:03:53
【问题描述】:

//参数标签 '(_:, _:)' 不匹配任何可用的重载第 12 行

 //接地

    var groundTexture = SKTexture(imageNamed: "ground")

    var sprite = SKSpriteNode(texture: groundTexture)
    sprite.setScale(2.0)
    sprite.position = CGPoint(x: self.size.width/2.0, y: sprite.size.height/2.0)
    self.addChild(sprite)

    var ground = SKNode()
    let size = CGSize.zero
    ground.position = CGPoint(x: 0, y: groundTexture.size().height)
    ground.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(self.frame.size.width, groundTexture.size().height * 2.0))

    ground.physicsBody?.isDynamic = false
    self.addChild(ground) <code>

【问题讨论】:

  • 第 12 行是哪一行?

标签: swift


【解决方案1】:

根据 Apple 的文档,CGSize 的 init 方法如下所示:init(width: Int, height: Int)。你可以在这里阅读:https://developer.apple.com/documentation/coregraphics/cgsize/1456247-init

所以你需要做的是改变这一行:

ground.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(self.frame.size.width, groundTexture.size().height * 2.0))

对此:

ground.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: self.frame.size.width, height: groundTexture.size().height * 2.0))

【讨论】:

    猜你喜欢
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    相关资源
    最近更新 更多