cocos2d - 如何从颜色中提取rgb

时间:2011-07-07 14:19:27

标签: iphone xcode cocos2d-iphone

我正在制作游戏的最后一部分,它会告诉你你的分数是多少。我想让它成为flash,动态和动画,所以我希望得分总计上升,我计划通过使得分数显示的文本更接近每个抽奖活动的实际得分,直到达到总数分数。

但是,我希望得分的数字在增量时闪烁,然后淡出。我计划通过从显示一步的分数中提取最后一位数字,然后将其与当前显示的分数中的最后一位数字进行比较来实现此目的。然后,如果它们不同,我会将最后一位数的颜色从白色设置为橙色。这将发生在每个数字上。

但后来我希望数字再次淡化为白色,所以我需要帮助(我到处寻找,找不到答案)是我需要得到每个字母的颜色,然后合并它变成了白色。但我不知道如何获得红色,绿色和蓝色组件。 这是我到目前为止所得到的:

-(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] ] ];
    }
}

然后我需要一个名为mergeFont的函数,它接受颜色的输入,使其更白,然后返回该颜色。我甚至不确定存储的颜色是什么 - 它是一个int吗?

感谢

1 个答案:

答案 0 :(得分:2)

在ccColor3B对象中,每个值都存储为GLubyte

来自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};

来源:ccTypes API