Tom
Tom

Reputation: 1

cocos2d - how to extract rgb from color

i'm making the final part of my game where it tells you what your score is. I wanted to make it flash, dynamic and animated, so i want the score to sort of total up, which i plan to do by making the text displayed by the score closer to the actual score in each draw event, until it reaches the total score.

However, i want the digits of the score to flash as they increment, and then fade. I plan to do this by extracting the last digit from the score that was displayed one step away, and then comparing it to the last digit from the score that is currently displayed. Then, if they are different, i will set the color of the last digit from white to orange. This will happen for every digit.

But then i want the digits to fade back down to white again, so what i need help with (i've looked everywhere and can't find answer) is i need to get the color of every letter, and then merge it into white. but i don't know how to get the red, green and blue components. here's what i've got so far:

-(BOOL) colourCount:(CCLabelBMFont*)label currentNo:(int)cNo targetNo:(int)tNo {
    CCArray *characters = [label children];

    //-------The code for making certain letters orange will go here----------

    //below makes the color of every letter more white
    for (int i=0; i++; i<[characters count]) {
        [(CCSprite *)[characters objectAtIndex:[characters count]-i] setColor: [self mergeFont: [(CCSprite *)[characters objectAtIndex:[characters count]] color] ] ];
    }
}

and then i need a function called mergeFont that takes an input of a color, makes it more white, and then returns that color. I'm not even sure what a color is stored as though - is it an int?

thanks

Upvotes: 0

Views: 1493

Answers (1)

eazimmerman
eazimmerman

Reputation: 609

In ccColor3B objects each value is stored as a GLubyte

Source code from ccType:

typedef struct _ccColor3B
{
         GLubyte r;
         GLubyte g;
         GLubyte b;
 } ccColor3B;

 static inline ccColor3B
 ccc3(const GLubyte r, const GLubyte g, const GLubyte b)
 {
         ccColor3B c = {r, g, b};
         return c;
}
//ccColor3B predefined colors
static const ccColor3B ccWHITE = {255,255,255};
static const ccColor3B ccYELLOW = {255,255,0};
static const ccColor3B ccBLUE = {0,0,255};
static const ccColor3B ccGREEN = {0,255,0};
static const ccColor3B ccRED = {255,0,0};
static const ccColor3B ccMAGENTA = {255,0,255};
static const ccColor3B ccBLACK = {0,0,0};
static const ccColor3B ccORANGE = {255,127,0};
static const ccColor3B ccGRAY = {166,166,166};

Source:ccTypes API

Upvotes: 2

Related Questions