var colorize1 = SKAction.colorizeWithColor(.redColor(), colorBlendFactor: 1.0, duration: 0.3)
var colorize2 = SKAction.colorizeWithColor(.greenColor(), colorBlendFactor: 1.0, duration: 0.3)
var colorize3 = SKAction.colorizeWithColor(.blueColor(), colorBlendFactor: 1.0, duration: 0.3)
var actions = [colorize1, colorize2, colorize3]
var randomIndex = Int(arc4random_uniform(3))
var action = actions[randomIndex]
let seconds = 0.14
let delay = seconds * Double(NSEC_PER_SEC) // nanoseconds per seconds
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
self.Ball.runAction(action)
})
}
因此,此代码将我的球着色为红色,绿色或蓝色。有没有办法检查我在游戏运行时选择了哪种颜色?它不只是选择一个然后它就完成了,我的球的颜色每隔几秒就会改变一次。如何构造一个if语句,如:“如果我的动作选择的随机颜色是红色然后打印(”嘿“)或类似的东西?
编辑我是swift和xCode的新手,所以我可能需要更深入的帮助。
答案 0 :(得分:0)
您只需打开randomIndex
:
switch randomIndex {
case 0:
print("colorize1")
case 1:
print("colorize2")
case 2:
print("colorize3")
}