-1

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

- (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 似乎没有实现“反向”,这是有道理的。有没有其他方法可以使用 CCAction 在间隔内去除添加的色调?

4

3 回答 3

3
  1. CCSprite's default color is ccWhite, {255, 255, 255}, so if you want to make sprite lighter, you'll have to subclass CCSprite/write shader to use additive coloring.

  2. Just tint it back:

    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]];
    
于 2012-10-26T18:16:50.713 回答
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));

工作正常克雷里,谢谢!我已经给你加分了:)。

于 2014-12-31T23:07:55.640 回答
0

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

于 2012-10-26T12:13:35.427 回答