I have a function that will randomly output a SKColor.
func getRandomColor() -> SKColor{
let randomaval = arc4random_uniform(4)
var color = SKColor()
switch(randomaval)
{
case 0:
color = redColor
case 1:
color = greenColor
case 2:
color = blueColor
case 3:
color = yellowColor
default:()
}
return color
}
When two bodies collide I call this function to change colors
aball.color = getRandomColor()
if aball.color == redColor && getRandomColor() == redColor {
aball.color = getRandomColor() //to set the color to something other than red
aball.colorBlendFactor = 1.0
}
What I want to do is that, when I say aball.color = getRandomColor()
, if getRandomColor()
is redColor
again, it needs to run the if
statement again till the function returns something other than redColor
. Most of the time, when my if
condition is true, it calls redColor
again and I can't understand how to avoid that. I basically want a different color to be returned everytime getRandomColor
is called. How do I accomplish that?