我尝试下一个代码但得到以下错误:"一行上的连续语句必须用';'"分隔。我哪里错了?
let moveLeft = SKAction.customActionWithDuration(0.0, actionBlock: {node: SKNode!, elapsedTime: CGFloat) -> Void in
node.physicsBody?.velocity = CGVectorMake(0.5, 0.5)
})
答案 0 :(得分:2)
闭包中的参数就像一个元组,它们两边都需要括号。你也应该明确地展开节点的physicsBody(如果它可能是零,则使用if let
。)
let moveLeft = SKAction.customActionWithDuration(0.0, actionBlock: { (node: SKNode!, elapsedTime: CGFloat) -> Void in
node.physicsBody!.velocity=CGVector(dx: 0.5, dy: 0.5)
})