Cocos2d iphone cocos2d去除色斑
我正在尝试为我的精灵实现高光动画。精灵应高亮显示为给定颜色,并逐渐反转回其原始颜色,代码如下:Cocos2d iphone cocos2d去除色斑,cocos2d-iphone,ccaction,Cocos2d Iphone,Ccaction,我正在尝试为我的精灵实现高光动画。精灵应高亮显示为给定颜色,并逐渐反转回其原始颜色,代码如下: - (void)highlight { CCTintTo *tintAction = [CCTintTo actionWithDuration:0.1 red:255 green:255 blue:255]; CCTintTo *tintBackAction = [tintAction reverse]; CCSequence *sequence = [CCSequence
- (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在一段时间内删除添加的色调?您可以在开始着色之前存储以前的颜色,然后仅使用初始RGB值创建CCTINTO
CCSprite
的默认颜色是ccWhite
,{255,255},因此如果
要使sprite更亮,您必须子类CCSprite
/write着色器才能使用附加着色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]];
很好,克里里,谢谢!我已经给了你一个加号:)。试过了,但没有用。我在tintAction之前没有为CCSprite设置任何颜色,并且使用此方法不会删除CCTintTo添加的色调。1。“使用加法着色的子类CCSprite/write着色器”这听起来非常有趣。如果您有时间的话,我将非常感谢您在cocos2d中提供更多关于您的意思以及如何做到这一点的详细信息。2.我已经试过了。正如您所说,CCSprite的默认颜色是ccWHITE,这段代码只存储ccWHITE,基本上在我的代码中重复“tintAction”操作,没有任何效果。不会将精灵恢复到其原始状态。用谷歌搜索它。有两个教程,一个是关于叠加着色的覆盖绘制方法(对于COCOS2D1.x),另一个是关于为COCOS2D2.x编写着色器的。我一定要用谷歌搜索它。谢谢你的时间和宝贵的意见。回复:“无效”。嗯,你做错了什么。
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));