SKColor comparison works in simulator not on iPhone 5s, and with standard colors not custom ones

♀尐吖头ヾ 提交于 2020-01-26 02:44:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!