0

I've found a strange behavior while using the iPhone 5S as development-target(Simulator and real device).

I'd like to scale a SKSpriteNode with an SKAction.scaleTo. This works fine on the iPhone 4S and the iPhone 5 simulator(Tested with iOS 7.0.3 and iOS 8).

But on the iPhone 5S simulator, the node doesn't scale. Also on my real iPhone 5S it doesn't scale.

Here is my code:

for tile in tileArray{
            if(tile.color == searchColor){
                var action = SKAction.scaleTo(0.5, duration: 0.5)
                var action2 = SKAction.scaleTo(1, duration: 0.5)
                tile.runAction(SKAction.repeatActionForever(SKAction.sequence([action, action2])))

            }
        }

EDIT:

I've now found out, that the if-block doesn't get called on the iPhone 5S. I don't know why. For the other iPhones it works.

But as you see, the two colors are the same:

UIDeviceRGBColorSpace 0.203922 0.286275 0.368627 1
UIDeviceRGBColorSpace 0.203922 0.286275 0.368627 1

How is that possible?

Important: Other SKaction.scaleTo actions are working without any problems.

Christian
  • 22,585
  • 9
  • 80
  • 106
  • Can you confirm it is running the sequence? AKA getting passed tile.color==searchcolor. – meisenman Sep 15 '14 at 14:04
  • @meisenman you are absolutely right. It doesn't get called, but the for-loop is working. But why? – Christian Sep 15 '14 at 14:22
  • Well at least we can narrow out some user specific bug causing your SKActions to be the problem. Hopefully someone else can step in with more knowledge of the color system. – meisenman Sep 15 '14 at 15:42

2 Answers2

0

You are not comparing colors, you are comparing pointer values:

if(tile.color == searchColor)

This tests whether tile.color and searchColor both point to the same memory address. Depending on how the color is created, these addresses may be different. Try testing the individual color components as in:

if (tile.color.r == seachColor.r && tile.color.g == searchColor.b && etc ..)

Note that equality for floating point values is "relative".

Community
  • 1
  • 1
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
0

The cause is the UIDeviceRGBColorSpace, which is different on the iPhone 5S. So I had to create an object-class which has also a name in it. Now I have to add the colornames to the class too, but I can compare the colors that way:

var color1 = ColorClass("myRed", color:theColor)
var color2 = ColorClass("myRed", color:theColor2)

if(color1.name == color2.name){

}

Of course this fix is really case-dependant. So for many others, this solution won't be good enough for their purposes.

Christian
  • 22,585
  • 9
  • 80
  • 106