add null pointer check, make code more robust

This commit is contained in:
andyque 2014-11-27 18:25:13 +08:00
parent f3e9af8100
commit 1bb60ab4bb
1 changed files with 28 additions and 8 deletions

View File

@ -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;
}