2

I have 25 circles on screen each with a random colour that has been generated from the declared colours and each names 'CIRCLE_1', 'CIRCLE_2' etc.

When matching the node.fillColor with the pre-defined colours, only the Yellow returns a value. Everything else remains at 0.

Can't see what I'm doing wrong/missing.

let SDRed = SKColor(red: 255/255, green: 61/255, blue: 61/255, alpha: 1.0)
let SDBlue = SKColor(red: 0/255, green: 175/255, blue: 255/255, alpha: 1.0)
let SDYellow = SKColor(red: 255/255, green: 255/255, blue: 0/255, alpha: 1.0)
let SDOrange = SKColor(red: 255/255, green: 128/255, blue: 0/255, alpha: 1.0)
let SDPink = SKColor(red: 255/255, green: 105/255, blue: 180/255, alpha: 1.0)
let SDGreen = SKColor(red: 144/255, green: 238/255, blue: 144/255, alpha: 1.0)
let SDDodgerBlue = SKColor(red: 30/255, green: 144/255, blue: 255/255, alpha: 1.0)



func checkAllColoursAvailable() -> Bool {


    var yellow = 0
    var blue = 0
    var pink = 0
    var green = 0
    var red = 0
    var orange = 0


    enumerateChildNodes(withName: "CIRCLE_*", using:
        { (node, stop) -> Void in
            print((node as! SKShapeNode).name!)

            let col: SKColor = (node as! SKShapeNode).fillColor

            if col == SDYellow {
                yellow = yellow + 1
            } else if col == SDGreen {
                green = green + 1
            } else if col == SDDodgerBlue {
                blue = blue + 1
            } else if col == SDOrange {
                orange = orange + 1
            } else if col == SDRed {
                red = red  + 1
            } else if col == SDPink {
                pink = pink + 1
            }
    })


    if yellow >= 1 && blue >= 1 && green >= 1 && orange >= 1 && red >= 1 && pink >= 1 {
        return true
    } else {
        return false
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ryann786
  • 289
  • 4
  • 12
  • See if this [SO post](http://stackoverflow.com/a/39935507/3402095) helps in some way. – Whirlwind Dec 18 '16 at 21:24
  • Hi, I have the same problem here. Even used the `UIColor` compare code from the mentioned above comment - it's notworking. Have you found a solution, why the SKShapeNode alters the `cGColor` of a pre-defined `UIColor`? – piotr_ch Oct 06 '18 at 19:03
  • @PiotrCh I found that by creating a defined node and assigning the node a variable 'colour' as a string and named that colour, then compare the 2 nodes values with each other to see if they match :) Hope this helps – Ryann786 Nov 26 '18 at 22:40

0 Answers0