如何在动作边界停止SKAction.repeatActionForever动作?

时间:2015-06-26 20:27:11

标签: ios swift sprite-kit

我创建了一系列SpriteKit动作,然后在节点上永远重复,但我想最终停止。我的序列向左,向右和向左旋转磁盘,然后再次启动之前返回原始旋转。但是,当我删除操作时,它会在没有完成的情况下停止,因此原始旋转不会恢复。

我可以保存原始旋转状态并恢复它,但我想知道是否有办法告诉SpriteKit只在中断序列边界的动作?

func wiggle() -> SKAction {
    let wiggleLeft = SKAction.rotateByAngle(+0.04, duration: 0.1)
    let wiggleRight = SKAction.rotateByAngle(-0.08, duration: 0.2)
    let wiggleBack = SKAction.rotateByAngle(+0.04, duration: 0.1)
    let wiggle = SKAction.sequence([wiggleLeft, wiggleRight, wiggleBack])
    let wiggleForever = SKAction.repeatActionForever(wiggle)
    return wiggleForever
}

disk.runAction(wiggle(), withKey: "wiggle")
...
disk.removeActionForKey("wiggle")    // unfortunately stops mid-wiggle

1 个答案:

答案 0 :(得分:1)

disk.removeActionForKey("wiggle")之后添加以下代码:     disk.runAction.rotateToAngle(/*desired final angle of rotation*/)