diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index 8d6197e5e4..3b61062231 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -101,15 +101,25 @@ void LoadingBar::setDirection(cocos2d::ui::LoadingBar::Direction direction) case Direction::LEFT: _barRenderer->setAnchorPoint(Vec2(0.0f,0.5f)); _barRenderer->setPosition(Vec2(0,_contentSize.height*0.5f)); - if (!_scale9Enabled) { - _barRenderer->getSprite()->setFlippedX(false); + if (!_scale9Enabled) + { + auto innerSprite = _barRenderer->getSprite(); + if (nullptr != innerSprite) + { + innerSprite->setFlippedX(false); + } } break; case Direction::RIGHT: _barRenderer->setAnchorPoint(Vec2(1.0f,0.5f)); _barRenderer->setPosition(Vec2(_totalLength,_contentSize.height*0.5f)); - if (!_scale9Enabled) { - _barRenderer->getSprite()->setFlippedX(true); + if (!_scale9Enabled) + { + auto innerSprite = _barRenderer->getSprite(); + if (nullptr != innerSprite) + { + innerSprite->setFlippedX(true); + } } break; } @@ -148,14 +158,24 @@ void LoadingBar::loadTexture(const std::string& texture,TextureResType texType) { case Direction::LEFT: _barRenderer->setAnchorPoint(Vec2(0.0f,0.5f)); - if (!_scale9Enabled) { - _barRenderer->getSprite()->setFlippedX(false); + if (!_scale9Enabled) + { + auto innerSprite = _barRenderer->getSprite(); + if (nullptr != innerSprite) + { + innerSprite->setFlippedX(false); + } } break; case Direction::RIGHT: _barRenderer->setAnchorPoint(Vec2(1.0f,0.5f)); - if (!_scale9Enabled) { - _barRenderer->getSprite()->setFlippedX(true); + if (!_scale9Enabled) + { + auto innerSprite = _barRenderer->getSprite(); + if (nullptr != innerSprite) + { + innerSprite->setFlippedX(true); + } } break; }