Swift : SKSpriteNode 重复变色

Swift : Color Changing SKSpriteNode on repeat

我想改变我的 SKSpriteNode 的颜色,类似于频闪灯,它如何不断改变颜色然后重复。我可以用这样的 UIView 做到这一点:

UIView.animateWithDuration(2, delay: 0.0, options:[UIViewAnimationOptions.Repeat, UIViewAnimationOptions.Autoreverse], animations: {
self.view.backgroundColor = UIColor.blackColor()
self.view.backgroundColor = UIColor.greenColor()
self.view.backgroundColor = UIColor.grayColor()
self.view.backgroundColor = UIColor.redColor()
}, completion: nil)

但我想对 sksprite 节点执行此操作。我做了这样的事情并创建了一堆但是这是有问题的,我觉得可能有更好的方法。

let changeBlue = SKAction.colorizeWithColor(UIColor.blueColor(), colorBlendFactor: 1.0, duration: 2.0)
self.runAction(changeBlue)

let changeRed = SKAction.colorizeWithColor(UIColor.redColor(), colorBlendFactor: 1.0, duration: 2.0)
self.runAction(changeRed)

您可能正在寻找 sequence(_:)。请参阅 SKAction 文档中的 Creating Actions That Combine or Repeat Other Actions。此外,repeatActionForever(_:) 使操作无限重复。

let colorBlue = SKAction.colorizeWithColor(UIColor.blueColor(), colorBlendFactor: 1.0, duration: 2.0)
let colorRed = SKAction.colorizeWithColor(UIColor.redColor(), colorBlendFactor: 1.0, duration: 2.0)
let colorizeSequence = SKAction.sequence([colorBlue, colorRed])
runAction(SKAction.repeatActionForever(colorizeSequence))