lundi 13 juin 2016

Randomly coloring sprites, but needs restrictions

I have a very, very specific issue.

I have six rectangles.

[] = a rectangle.

They have a format like this on the screen: [] [][] [][] []. They all need to be a random color between red, green, and blue.

       var colorize1 = SKAction.colorizeWithColor(.redColor(), colorBlendFactor: 1.0, duration: 0.1)

        var colorize2 = SKAction.colorizeWithColor(.greenColor(), colorBlendFactor: 1.0, duration: 0.1)

        var colorize3 = SKAction.colorizeWithColor(.blueColor(), colorBlendFactor: 1.0, duration: 0.1)

       var actions = [colorize1, colorize2, colorize3]

         var randomIndex = Int(arc4random_uniform(3))

       var action = actions[randomIndex]





        greenWall1.runAction(action)
        greenWall2.runAction(action)

This code does that. BUT, I can't have the same color adjacent to the next pair.

[Wall1] [Wall2][Wall3] [Wall4][Wall5] [Wall6]

1 and 2 are pairs. 3 and 4 are pairs, etc.

Wall 1 and Wall 2 need to be the same color since they're pairs. 3 and 4 need to be a different random color. 5 and 6 need to be a different than WallPair1 and WallPair2.

Right now, I get up to three of the same colors on each pair. Maybe all reds.

I need to write code that says "if pair 1 (wall1 and wall2) are red for example, then the second pair(wall3 and wall4), and the third pair(wall5 and wall6), can't be red.

I can't figure this out.

Thanks so much for your help.




Aucun commentaire:

Enregistrer un commentaire