问题
The following code fails on an iPhone 5s, meaning it reaches the else case, but works fine in the simulator. It also works fine if we use standard colors for red and blue (i.e., 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?
回答1:
Is there a specific reason 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")
}
来源:https://stackoverflow.com/questions/30087625/skcolor-comparison-works-in-simulator-not-on-iphone-5s-and-with-standard-colors