This code colorizes my ball.
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)
})
}
This code colorizes my walls.
var colorBucket = [UIColor]()
func randomColor() -> UIColor {
if colorBucket.isEmpty {
fillBucket()
}
let randomIndex = Int(arc4random_uniform(UInt32(colorBucket.count)))
let randomColor = colorBucket[randomIndex]
colorBucket.removeAtIndex(randomIndex)
return randomColor
}
func fillBucket() {
colorBucket = [UIColor.redColor(), UIColor.greenColor(), UIColor.blueColor()]
}
I need to write an if statement that detects whether or not the ball and wall are the same color when I collide with an spritekitnode() located in between my walls.
I've tried these:
if Wall1.color == UIColor.redColor() && Wall2.color == UIColor.redColor() && Ball.color != UIColor.redColor {
died = true
}
My main issue is writing the if statement that determines if the ball and walls are the same color. I have the collision part down. Thank you so much for your help.
Aucun commentaire:
Enregistrer un commentaire