From ab369b56ff6fd087bcf82695c41320242b90a9ec Mon Sep 17 00:00:00 2001 From: woaicandy Date: Thu, 10 Mar 2022 16:00:04 +0800 Subject: [PATCH] fix position errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. I used initWithSpriteFrame and spriteFrame->getOffset() is not zero, so _unflippedOffsetPositionFromCenter is not zero. 2. used initWithFile ,the position will be wrong,because _unflippedOffsetPositionFromCenter is not reset. --- cocos/2d/CCSprite.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index eb20451354bf..ea569ef26764 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -261,7 +261,10 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) setDirty(false); _flippedX = _flippedY = false; - + + //need reset if _texture is changed + _unflippedOffsetPositionFromCenter = Vec2::ZERO; + // default transform anchor: center setAnchorPoint(Vec2::ANCHOR_MIDDLE);