Comparison SKColor does not work in the simulator on iPhone 5, but with standard non-standard colors

The following code crashes on iPhone 5, which means that it reaches the else case, but works fine in the simulator. It also works great if we use standard colors for red and blue (e.g. SKColor.blueColor (), SKColor.redColor ())

let BlueColor = SKColor(red: 0/255.0, green: 185/255.0, blue: 252/255.0, alpha: 1.0) let RedColor = SKColor(red: 250/255.0, green: 50/255.0, blue: 53/255.0, alpha: 1.0) let dot = SKSpriteNode(imageNamed: "dot50") dot.colorBlendFactor = 1.0 dot.color = BlueColor if (dot.color == BlueColor) { println("Blue!") } else if (dot.color == RedColor) { println("Red!") } else { println("Nooooo! This shouldn't happen") } 

Any clues why?

0
ios iphone swift sprite-kit
source share
1 answer

Is there a specific reason why you need to identify these nodes by their color? Perhaps you could do something like this ...

 let BlueColor = SKColor(red: 0/255.0, green: 185/255.0, blue: 252/255.0, alpha: 1.0) let RedColor = SKColor(red: 250/255.0, green: 50/255.0, blue: 53/255.0, alpha: 1.0) let dot = SKSpriteNode(imageNamed: "dot50") dot.colorBlendFactor = 1.0 dot.color = BlueColor dot.name = "BlueNode" if (dot.name == "BlueNode") { foundBlueColor() println("Blue!") } else if (dot.name == "RedNode") { foundRedColor() println("Red!") } else { println("Nooooo! This shouldn't happen") } 
0
source share

All Articles