New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Animation reset color and opacity of Sprite #15696
Comments
Any progress in this issue? I have the same problem here (cocos2dx 3.12). Besides, it seems that Animate/Animation resets |
I've found that this issue is related to void Sprite::setSpriteFrame(SpriteFrame *spriteFrame)
{
// retain the sprite frame
// do not removed by SpriteFrameCache::removeUnusedSpriteFrames
if (_spriteFrame != spriteFrame)
{
CC_SAFE_RELEASE(_spriteFrame);
_spriteFrame = spriteFrame;
spriteFrame->retain();
}
_unflippedOffsetPositionFromCenter = spriteFrame->getOffset();
Texture2D *texture = spriteFrame->getTexture();
// update texture before updating texture rect
if (texture != _texture)
{
setTexture(texture);
}
// update rect
_rectRotated = spriteFrame->isRotated();
setTextureRect(spriteFrame->getRect(), _rectRotated, spriteFrame->getOriginalSize());
if(spriteFrame->hasPolygonInfo())
{
_polyInfo = spriteFrame->getPolygonInfo();
}
if (spriteFrame->hasAnchorPoint())
{
setAnchorPoint(spriteFrame->getAnchorPoint());
}
} Every frame, I've managed to fix the issue by making the following changes to if(spriteFrame->hasPolygonInfo())
{
_polyInfo = spriteFrame->getPolygonInfo();
if (_flippedX) flipX();
if (_flippedY) flipY();
updateColor();
} And refactored void Sprite::setFlippedX(bool flippedX)
{
if (_flippedX != flippedX)
{
_flippedX = flippedX;
flipX();
}
}
void Sprite::setFlippedY(bool flippedY)
{
if (_flippedY != flippedY)
{
_flippedY = flippedY;
flipY();
}
}
void Sprite::flipX() {
for (ssize_t i = 0; i < _polyInfo.triangles.vertCount; i++) {
auto& v = _polyInfo.triangles.verts[i].vertices;
v.x = _contentSize.width -v.x;
}
if (_textureAtlas) {
setDirty(true);
}
}
void Sprite::flipY() {
for (ssize_t i = 0; i < _polyInfo.triangles.vertCount; i++) {
auto& v = _polyInfo.triangles.verts[i].vertices;
v.y = _contentSize.height -v.y;
}
if (_textureAtlas) {
setDirty(true);
}
} Hope this issue gets officially fixed in an upcoming release. |
When I change color or opacity of Sprite and run Animate, color and opacity will be back to default in every setSpriteFrame.
This happens only if TexturePacker algorithm is polygon.
http://discuss.cocos2d-x.org/t/animation-reset-color-and-opacity-of-sprite/29452
The text was updated successfully, but these errors were encountered: