Animation reset color and opacity of Sprite

If I change color of the sprite and run Animate, color would be back to default.
It seems color has returned to white in every setSpriteFrame.
For this reason, if I run Tint action and Animate action simultaneously, the sprite would blink.
I want the sprite to keep the color in animation, how would can it be?
I’m using cocos2dx v.3.10.
Thank you.

edit:
I found that Sprite flickering happens only if TexturePacker layout algorithm is polygon.

Add a custom event listener for AnimationFrameDisplayedNotification events.

...
Animate* animate = Animate::create(animation);
RepeatForever* repeat = RepeatForever::create(animate);
repeat->setTag(TagAnimate);

/// Add a dummy value map for each frame so that 
/// AnimationFrameDisplayedNotification events can be fired.
ValueMap dummyMap;
dummyMap["dummy"] = "dummy";
for (auto&& frame : animation->getFrames()) {
    frame->setUserInfo(dummyMap);
}
    
getEventDispatcher()->addCustomEventListener(AnimationFrameDisplayedNotification,
                                             [this](cocos2d::EventCustom* event) {
                                                 // Reset the sprite's color.
                                                 _sprite->setColor(_sprite->getColor());
                                             });
    
_sprite->stopActionByTag(TagAnimate);
_sprite->runAction(repeat);
...

Another way is to subclass cocos2d::Sprite and override virtual void setSpriteFrame(SpriteFrame* newFrame) like this:

void MySprite::setSpriteFrame(SpriteFrame* newFrame) {
    Sprite::setSpriteFrame(newFrame);
    setColor(getColor);
}
1 Like

Thank you.

I feel like this is a bug. Prob should submit issue on github?

I submitted the issue.