Swift 如何在SKAction序列中添加一个返回void的函数?

Swift 如何在SKAction序列中添加一个返回void的函数?,swift,skspritenode,Swift,Skspritenode,我将粒子发射器添加到SKSpriteNode对象(球)以在其移动时生成轨迹。以下代码将球返回其原始位置: let moveAction = SKAction.move(to: CGPoint(x: origNP.x, y: origNP.y), duration: 0.3) let doneTrail: Void = moveThis.removeAllChildren() let sequence = SKAction.sequence([moveAction, doneTrail]) mov

我将粒子发射器添加到SKSpriteNode对象(球)以在其移动时生成轨迹。以下代码将球返回其原始位置:

let moveAction = SKAction.move(to: CGPoint(x: origNP.x, y: origNP.y), duration: 0.3)
let doneTrail: Void = moveThis.removeAllChildren()
let sequence = SKAction.sequence([moveAction, doneTrail])
moveThis.run(sequence)
我的目标是,在球回到原来的位置之前,我不想移除发射器。但是,上面的代码不起作用,因为我得到了错误:

无法将“Void”类型的值转换为预期的元素类型 “SKAction”

因此,我现在的做法是:

let moveAction = SKAction.move(to: CGPoint(x: origNP.x, y: origNP.y), duration: 0.3)
let sequence = SKAction.sequence([moveAction])
moveThis.run(sequence)
moveThis.removeAllChildren()
但很明显,在球返回之前,轨迹消失了


有没有一种方法可以将void returning方法添加到SKAction序列中?

当您想将一段代码转换为
SKAction
时,您可以使用:

既然
doneTrail
是一个
SKAction
SKAction.sequence([moveAction,doneTrail])
应该编译

let doneTrail = SKAction.run { moveThis.removeAllChildren() }