//参数标签“(:,:)”与任何可用的重载行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>
最佳答案
根据苹果的文档,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))
关于swift - swift cgsize错误参数标签'(_ :, _ :)'与任何可用的重载都不匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52140206/