I want the color information of my sprite to update each time it changes in my scene.
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
}
let redColor = UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
let greenColor = UIColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0)
let blueColor = UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
func fillBucket() {
colorBucket = [redColor, greenColor, blueColor]
}
After creating these functions, I use them here. The wall is the sprite whose color information I want to update.
action = SKAction.colorizeWithColor(randomColor(), colorBlendFactor: 1.0, duration: 0.1)
Wall1.runAction(action)
I want to be able to see this change as it occurs in my scene. So if I were to print(Wall1.color) I should receive: UIDeviceRGBColorSpace 1 0 0 1, UIDeviceRGBColorSpace 0 1 0 1, or UIDeviceRGBColorSpace 0 0 1 1. (Red, Green, or Blue.)
Right now, when I print the color information for Wall1, I get UIDeviceRGBColorSpace 1 1 1 0.
How do I update this information when it happens? When the random color selected is blueColor, it should print UIDeviceRGBColorSpace 0 0 1 1 as an example.
Aucun commentaire:
Enregistrer un commentaire