【问题标题】:SKAction.customActionWithDuration Consecutive statements on a line must be separated by ';'SKAction.customActionWithDuration 一行上的连续语句必须用';'分隔
【发布时间】:2023-03-15 15:50:01
【问题描述】:

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

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

【问题讨论】:

    标签: ios swift sprite-kit


    【解决方案1】:

    闭包中的参数就像一个元组,两边都需要括号。此外,您应该明确解开节点的物理体(如果可能为 nil,则使用 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)
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-18
      • 2023-01-25
      • 1970-01-01
      相关资源
      最近更新 更多