Skip to content
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

Fix polygon sprite bug of resetting flip and color information #18085

Merged
merged 1 commit into from Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 43 additions & 34 deletions cocos/2d/CCSprite.cpp
Expand Up @@ -1433,23 +1433,7 @@ void Sprite::setFlippedX(bool flippedX)
if (_flippedX != flippedX)
{
_flippedX = flippedX;

if (_renderMode == RenderMode::QUAD_BATCHNODE)
{
setDirty(true);
}
else if (_renderMode == RenderMode::POLYGON)
{
for (ssize_t i = 0; i < _polyInfo.triangles.vertCount; i++) {
auto& v = _polyInfo.triangles.verts[i].vertices;
v.x = _contentSize.width -v.x;
}
}
else
{
// RenderMode:: Quad or Slice9
updatePoly();
}
flipX();
}
}

Expand All @@ -1463,23 +1447,7 @@ void Sprite::setFlippedY(bool flippedY)
if (_flippedY != flippedY)
{
_flippedY = flippedY;

if (_renderMode == RenderMode::QUAD_BATCHNODE)
{
setDirty(true);
}
else if (_renderMode == RenderMode::POLYGON)
{
for (ssize_t i = 0; i < _polyInfo.triangles.vertCount; i++) {
auto& v = _polyInfo.triangles.verts[i].vertices;
v.y = _contentSize.height -v.y;
}
}
else
{
// RenderMode:: Quad or Slice9
updatePoly();
}
flipY();
}
}

Expand All @@ -1488,6 +1456,44 @@ bool Sprite::isFlippedY(void) const
return _flippedY;
}

void Sprite::flipX() {
if (_renderMode == RenderMode::QUAD_BATCHNODE)
{
setDirty(true);
}
else if (_renderMode == RenderMode::POLYGON)
{
for (ssize_t i = 0; i < _polyInfo.triangles.vertCount; i++) {
auto& v = _polyInfo.triangles.verts[i].vertices;
v.x = _contentSize.width -v.x;
}
}
else
{
// RenderMode:: Quad or Slice9
updatePoly();
}
}

void Sprite::flipY() {
if (_renderMode == RenderMode::QUAD_BATCHNODE)
{
setDirty(true);
}
else if (_renderMode == RenderMode::POLYGON)
{
for (ssize_t i = 0; i < _polyInfo.triangles.vertCount; i++) {
auto& v = _polyInfo.triangles.verts[i].vertices;
v.y = _contentSize.height -v.y;
}
}
else
{
// RenderMode:: Quad or Slice9
updatePoly();
}
}

//
// MARK: RGBA protocol
//
Expand Down Expand Up @@ -1591,6 +1597,9 @@ void Sprite::setSpriteFrame(SpriteFrame *spriteFrame)
{
_polyInfo = spriteFrame->getPolygonInfo();
_renderMode = RenderMode::POLYGON;
if (_flippedX) flipX();
if (_flippedY) flipY();
updateColor();
}
if (spriteFrame->hasAnchorPoint())
{
Expand Down
3 changes: 3 additions & 0 deletions cocos/2d/CCSprite.h
Expand Up @@ -661,6 +661,9 @@ CC_CONSTRUCTOR_ACCESS :
void updatePoly();
void updateStretchFactor();

virtual void flipX();
virtual void flipY();

//
// Data used when the sprite is rendered using a SpriteSheet
//
Expand Down