SKAction.customActionWithDuration行上的连续语句必须用';'分隔

时间:2015-02-08 18:31:47

标签: ios swift sprite-kit

我尝试下一个代码但得到以下错误:"一行上的连续语句必须用';'"分隔。我哪里错了?

let moveLeft = SKAction.customActionWithDuration(0.0, actionBlock: {node: SKNode!, elapsedTime: CGFloat) -> Void in
            node.physicsBody?.velocity = CGVectorMake(0.5, 0.5)
          })

1 个答案:

答案 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)
})