mirror of https://github.com/axmolengine/axmol.git
add null pointer check, make code more robust
This commit is contained in:
parent
f3e9af8100
commit
1bb60ab4bb
|
@ -101,15 +101,25 @@ void LoadingBar::setDirection(cocos2d::ui::LoadingBar::Direction direction)
|
||||||
case Direction::LEFT:
|
case Direction::LEFT:
|
||||||
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
|
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
|
||||||
_barRenderer->setPosition(Vec2(0,_contentSize.height*0.5f));
|
_barRenderer->setPosition(Vec2(0,_contentSize.height*0.5f));
|
||||||
if (!_scale9Enabled) {
|
if (!_scale9Enabled)
|
||||||
_barRenderer->getSprite()->setFlippedX(false);
|
{
|
||||||
|
auto innerSprite = _barRenderer->getSprite();
|
||||||
|
if (nullptr != innerSprite)
|
||||||
|
{
|
||||||
|
innerSprite->setFlippedX(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Direction::RIGHT:
|
case Direction::RIGHT:
|
||||||
_barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
|
_barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
|
||||||
_barRenderer->setPosition(Vec2(_totalLength,_contentSize.height*0.5f));
|
_barRenderer->setPosition(Vec2(_totalLength,_contentSize.height*0.5f));
|
||||||
if (!_scale9Enabled) {
|
if (!_scale9Enabled)
|
||||||
_barRenderer->getSprite()->setFlippedX(true);
|
{
|
||||||
|
auto innerSprite = _barRenderer->getSprite();
|
||||||
|
if (nullptr != innerSprite)
|
||||||
|
{
|
||||||
|
innerSprite->setFlippedX(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -148,14 +158,24 @@ void LoadingBar::loadTexture(const std::string& texture,TextureResType texType)
|
||||||
{
|
{
|
||||||
case Direction::LEFT:
|
case Direction::LEFT:
|
||||||
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
|
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
|
||||||
if (!_scale9Enabled) {
|
if (!_scale9Enabled)
|
||||||
_barRenderer->getSprite()->setFlippedX(false);
|
{
|
||||||
|
auto innerSprite = _barRenderer->getSprite();
|
||||||
|
if (nullptr != innerSprite)
|
||||||
|
{
|
||||||
|
innerSprite->setFlippedX(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Direction::RIGHT:
|
case Direction::RIGHT:
|
||||||
_barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
|
_barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
|
||||||
if (!_scale9Enabled) {
|
if (!_scale9Enabled)
|
||||||
_barRenderer->getSprite()->setFlippedX(true);
|
{
|
||||||
|
auto innerSprite = _barRenderer->getSprite();
|
||||||
|
if (nullptr != innerSprite)
|
||||||
|
{
|
||||||
|
innerSprite->setFlippedX(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue