Reputation: 71
I'm working on a game (Cocos2d + Obj-C) where I need to check if two colliding sprites has the same color or not. I've tried the following already:
if (ship.imageSprite.color == base.imageSprite.color)
{
{
NSLog(@"matching colors");
}
}
But I get compile time error: "invalid operands to binary expresson ('ccColor3B'(aka 'struct _ccColor3B') and 'ccColor3B')." What is the way to test two colors? Thanks.
Upvotes: 1
Views: 1534
Reputation: 1294
-(BOOL)isccColor3B:(ccColor3B)color1 theSame:(ccColor3B)color2{
if ((color1.r == color2.r) && (color1.g == color2.g) && (color1.b == color2.b)){
return YES;
} else {
return NO;
}
}
Upvotes: 6
Reputation: 64477
You'll have to test the ccColor3B components individually:
ccColor3B col1 = ship.imageSprite.color;
ccColor3B col2 = base.imageSprite.color;
if (col1.r == col2.r && col1.g == col2.g && col1.b == col2.b)
{
NSLog(@"matching colors");
}
Upvotes: 2