SKPhysicsBody "Extra argument 'size' in call"
SKPhysicsBody "Extra argument 'size' in call"
我想要实现的是使对象(物理体)的形状与纹理完全一样,以便将来只能单击纹理(而不是透明层)。
let fireLayer = SKSpriteNode(imageNamed: fireImage)
fireLayer.anchorPoint = CGPointMake(1, 0)
fireLayer.position = CGPointMake(size.width, 0)
fireLayer.zPosition = Layer.Z4st
var firedown = SKAction.moveToY(-200, duration: 0)
var fireup1 = SKAction.moveToY(10, duration: 1.2)
var fireup2 = SKAction.moveToY(0, duration: 0.2)
在这里,我正在尝试为 "cut out" 节点所需的对象创建实体。
fireLayer.physicsBody = SKPhysicsBody(texture: fireLayer, size: fireLayer.texture!.size())
现在,这里我得到一个错误"Extra argument 'size' in call"...虽然SKPhysicalBody有两个参数:texture和size。
fireLayer.name = "fireNode"
fireLayer.runAction(SKAction.sequence([firedown, wait1, fireup1, fireup2]))
addChild(fireLayer)
我做错了什么?
提前致谢!
此错误具有误导性。你的问题其实是第一个参数texture: fireLayer
。您需要设置 SKTexture
而不是 SKSpriteNode
。
您还应该更改初始化 SKSpriteNode 的方式并添加 SKTexture:
let fireLayerTexture = SKTexture(imageNamed: fireImage)
比:
let fireLayer = SKSpriteNode(texture: fireLayerTexture)
完成后,您可以像这样初始化 SKPhysicsBody
:
fireLayer.physicsBody = SKPhysicsBody(texture: fireLayerTexture, size: fireLayer.texture!.size())
我想要实现的是使对象(物理体)的形状与纹理完全一样,以便将来只能单击纹理(而不是透明层)。
let fireLayer = SKSpriteNode(imageNamed: fireImage)
fireLayer.anchorPoint = CGPointMake(1, 0)
fireLayer.position = CGPointMake(size.width, 0)
fireLayer.zPosition = Layer.Z4st
var firedown = SKAction.moveToY(-200, duration: 0)
var fireup1 = SKAction.moveToY(10, duration: 1.2)
var fireup2 = SKAction.moveToY(0, duration: 0.2)
在这里,我正在尝试为 "cut out" 节点所需的对象创建实体。
fireLayer.physicsBody = SKPhysicsBody(texture: fireLayer, size: fireLayer.texture!.size())
现在,这里我得到一个错误"Extra argument 'size' in call"...虽然SKPhysicalBody有两个参数:texture和size。
fireLayer.name = "fireNode"
fireLayer.runAction(SKAction.sequence([firedown, wait1, fireup1, fireup2]))
addChild(fireLayer)
我做错了什么? 提前致谢!
此错误具有误导性。你的问题其实是第一个参数texture: fireLayer
。您需要设置 SKTexture
而不是 SKSpriteNode
。
您还应该更改初始化 SKSpriteNode 的方式并添加 SKTexture:
let fireLayerTexture = SKTexture(imageNamed: fireImage)
比:
let fireLayer = SKSpriteNode(texture: fireLayerTexture)
完成后,您可以像这样初始化 SKPhysicsBody
:
fireLayer.physicsBody = SKPhysicsBody(texture: fireLayerTexture, size: fireLayer.texture!.size())