【发布时间】:2016-06-18 15:18:59
【问题描述】:
这是我正在开发的一个简单 SpriteKit 游戏的一些代码:
let square = SKShapeNode()
let square2 = SKShapeNode()
override func didMoveToView(view:SKView) {
var moveSquare: SKAction
moveSquare = SKAction.moveTo(CGPoint(x: someNumber, y:otherNumber), duration: NSTimeInterval(3))
square.runAction(SKAction.sequence([moveSquare1, SKAction.runBlock(checkIfSquareMatches(square)),SKAction.removeFromParent()]))
square2.runAction(SKAction.sequence([SKAction.waitForDuration(1.0),SKAction.runBlock(self.addChild(self.square2)) ,moveSquare, SKAction.removeFromParent()]))
}
func checkIfSquareMatches(shape:SKShapeNode) {...}
所以我有两个错误,一个在 square.runAction 行,另一个在 square2.runAction 行。第一个说
“无法将'()'类型的值转换为预期的参数类型'dispatch_block_t'(又名'@convention(block) () -> ()')”
第二个说的和上面一样,只是它说的是“type '()'”
“键入'Void'(又名'()')”
由于“(又名'()')”,我认为这是同一件事。
为什么会出现这些错误,我该如何解决?我在 stackoverflow 上看到了一篇关于在 SKAction.runBlock() 中运行函数的问题的帖子,但解决方案指出问题是您无法在 runBlock 中返回值,但我的函数没有返回任何值;它只会改变一些变量的值,所以我看不出问题。谢谢。
【问题讨论】:
标签: swift sprite-kit skaction