diff --git a/native/cocos/2d/CCClippingNode.cpp b/native/cocos/2d/CCClippingNode.cpp index 24aaa23044..241deb5651 100644 --- a/native/cocos/2d/CCClippingNode.cpp +++ b/native/cocos/2d/CCClippingNode.cpp @@ -107,9 +107,7 @@ bool ClippingNode::init() bool ClippingNode::init(Node *stencil) { - CC_SAFE_RELEASE(_stencil); - _stencil = stencil; - CC_SAFE_RETAIN(_stencil); + setStencil(stencil); return true; } diff --git a/native/cocos/2d/CCSprite.cpp b/native/cocos/2d/CCSprite.cpp index d3ca07ca09..c72f2ffeb5 100644 --- a/native/cocos/2d/CCSprite.cpp +++ b/native/cocos/2d/CCSprite.cpp @@ -144,7 +144,7 @@ Sprite* Sprite::create() bool Sprite::init() { - return initWithTexture(nullptr, Rect::ZERO ); + return initWithTexture(nullptr, Rect::ZERO, false); } bool Sprite::initWithTexture(Texture2D *texture) @@ -158,7 +158,7 @@ bool Sprite::initWithTexture(Texture2D *texture) Rect rect = Rect::ZERO; rect.size = texture->getContentSize(); - return initWithTexture(texture, rect); + return initWithTexture(texture, rect, false); } bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect) @@ -175,7 +175,7 @@ bool Sprite::initWithFile(const std::string& filename) { Rect rect = Rect::ZERO; rect.size = texture->getContentSize(); - return initWithTexture(texture, rect); + return initWithTexture(texture, rect, false); } return false; @@ -188,7 +188,7 @@ bool Sprite::initWithFile(const std::string &filename, const Rect& rect) Texture2D *texture = _director->getTextureCache()->addImage(filename); if (texture) { - return initWithTexture(texture, rect); + return initWithTexture(texture, rect, false); } return false; @@ -336,7 +336,7 @@ void Sprite::setTexture(const std::string &filename) Texture2D *texture = _director->getTextureCache()->addImage(filename); setTexture(texture); - + _unflippedOffsetPositionFromCenter = Vec2::ZERO; Rect rect = Rect::ZERO; if (texture) rect.size = texture->getContentSize(); diff --git a/native/cocos/ui/UIImageView.cpp b/native/cocos/ui/UIImageView.cpp index 7c1aedb3ed..4e333607b4 100644 --- a/native/cocos/ui/UIImageView.cpp +++ b/native/cocos/ui/UIImageView.cpp @@ -158,15 +158,18 @@ void ImageView::setTextureRect(const Rect &rect) else { auto sprite = _imageRenderer->getSprite(); + _imageRenderer->setScale9Enabled(false); if (sprite) { sprite->setTextureRect(rect); - setupTexture(); } else { CCLOG("Warning!! you should load texture before set the texture's rect!"); } + + _imageRenderer->setContentSize(rect.size); + setupTexture(); } }