From 681e9aa752334f73deda9fe98b62d7265d591032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felippe=20Dur=C3=A1n?= Date: Wed, 19 Jul 2017 00:08:12 -0300 Subject: [PATCH] Fix polygon sprite bug of resetting flip and color information in setSpriteFrame. (#18085) --- cocos/2d/CCSprite.cpp | 77 ++++++++++++++++++++++++------------------- cocos/2d/CCSprite.h | 3 ++ 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 63ebf0fab0..540d0a3db7 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -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(); } } @@ -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(); } } @@ -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 // @@ -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()) { diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index d16b885762..96b251eeeb 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -661,6 +661,9 @@ protected: void updatePoly(); void updateStretchFactor(); + virtual void flipX(); + virtual void flipY(); + // // Data used when the sprite is rendered using a SpriteSheet //