diff --git a/cocos/gui/UILoadingBar.cpp b/cocos/gui/UILoadingBar.cpp index 4822f0cca8..dd516a2190 100644 --- a/cocos/gui/UILoadingBar.cpp +++ b/cocos/gui/UILoadingBar.cpp @@ -219,30 +219,16 @@ void LoadingBar::setPercent(int percent) _percent = percent; float res = _percent/100.0; - int x = 0, y = 0; - switch (_renderBarTexType) - { - case UI_TEX_TYPE_PLIST: - { - Sprite* barNode = dynamic_cast(_barRenderer); - if (barNode) - { - Point to = barNode->getTextureRect().origin; - x = to.x; - y = to.y; - } - break; - } - default: - break; - } if (_scale9Enabled) { setScale9Scale(); } else { - static_cast(_barRenderer)->setTextureRect(Rect(x, y, _barRendererTextureSize.width * res, _barRendererTextureSize.height)); + Sprite* spriteRenderer = static_cast(_barRenderer); + Rect rect = spriteRenderer->getTextureRect(); + rect.size.width = _barRendererTextureSize.width * res; + spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.size); } } diff --git a/cocos/gui/UISlider.cpp b/cocos/gui/UISlider.cpp index a25e205d4f..30fc583524 100644 --- a/cocos/gui/UISlider.cpp +++ b/cocos/gui/UISlider.cpp @@ -339,7 +339,8 @@ void Slider::setPercent(int percent) percent = 0; } _percent = percent; - float dis = _barLength*(percent/100.0f); + float res = percent / 100.0f; + float dis = _barLength * res; _slidBallRenderer->setPosition(Point(-_barLength/2.0f + dis, 0.0f)); if (_scale9Enabled) { @@ -347,24 +348,10 @@ void Slider::setPercent(int percent) } else { - int x = 0, y = 0; - switch (_progressBarTexType) - { - case UI_TEX_TYPE_PLIST: - { - Sprite* barNode = dynamic_cast(_progressBarRenderer); - if (barNode) - { - Point to = barNode->getTextureRect().origin; - x = to.x; - y = to.y; - } - break; - } - default: - break; - } - static_cast(_progressBarRenderer)->setTextureRect(Rect(x, y, _progressBarTextureSize.width * (percent/100.0f), _progressBarTextureSize.height)); + Sprite* spriteRenderer = static_cast(_progressBarRenderer); + Rect rect = spriteRenderer->getTextureRect(); + rect.size.width = _progressBarTextureSize.width * res; + spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.size); } }