Attila.H
Attila.H

Reputation: 71

Cocos2d - compare two ccColor3B struct colors

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

Answers (2)

0xDE4E15B
0xDE4E15B

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

CodeSmile
CodeSmile

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

Related Questions