cocos2d删除色调

时间:2012-10-26 11:50:25

标签: cocos2d-iphone ccaction

我正在尝试为我的精灵实现一个高亮动画。精灵应该突出显示给定的颜色并逐渐反转回原始颜色,使用以下代码:

- (void)highlight {
    CCTintTo *tintAction = [CCTintTo actionWithDuration:0.1 red:255 green:255 blue:255];
    CCTintTo *tintBackAction = [tintAction reverse];

    CCSequence *sequence = [CCSequence actions: tintAction, tintBackAction, nil];
    [self runAction:sequence];
}

现在这个函数引发了一个异常,因为CCTintTo似乎没有实现'reverse',这是有道理的。有没有其他方法可以使用CCAction在一个时间间隔内删除添加的色调?

3 个答案:

答案 0 :(得分:3)

  1. CCSprite的默认颜色为ccWhite,{255,255,255},所以如果你 想让精灵变得更亮,你必须继承CCSprite /写着色器才能使用加色。

  2. 只是回味:

    CCColor3B oldColor = sprite.color;
    CCTintTo *tintTo = [CCTintTo actionWithDuration:t red:r green:g blue:b];
    CCTintTo *tintBack = [CCTintTo actionWithDuration:t red:oldColor.r green:oldColor.g blue:oldColor.b];
    [sprite runAction:[CCSequence actions: tintTo, tintBack, nil]];
    

答案 1 :(得分:0)

您可以在开始色调之前存储以前的颜色,然后只使用初始RGB值创建CCTintTo。

答案 2 :(得分:0)

对于Cocos2dx(C ++)

ccColor3B oldColor = sprite->getColor();
        CCTintTo* action = CCTintTo::create(0.5f, 127, 255, 127);
        CCTintTo* actionReverse = CCTintTo::create(0.5f, oldColor.r, oldColor.g, oldColor.b);;
        sprite->runAction(CCSequence::create(action, actionReverse, NULL));

工作正常Kreiri,谢谢!我已经给你了一个加号:)。