Fixed bugs

This commit is contained in:
CaiWenzhi 2013-12-27 17:58:00 +08:00
parent 495e574f44
commit b2da9d2da5
2 changed files with 10 additions and 37 deletions

View File

@ -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<Sprite*>(_barRenderer);
if (barNode)
{
Point to = barNode->getTextureRect().origin;
x = to.x;
y = to.y;
}
break;
}
default:
break;
}
if (_scale9Enabled)
{
setScale9Scale();
}
else
{
static_cast<Sprite*>(_barRenderer)->setTextureRect(Rect(x, y, _barRendererTextureSize.width * res, _barRendererTextureSize.height));
Sprite* spriteRenderer = static_cast<Sprite*>(_barRenderer);
Rect rect = spriteRenderer->getTextureRect();
rect.size.width = _barRendererTextureSize.width * res;
spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.size);
}
}

View File

@ -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<Sprite*>(_progressBarRenderer);
if (barNode)
{
Point to = barNode->getTextureRect().origin;
x = to.x;
y = to.y;
}
break;
}
default:
break;
}
static_cast<Sprite*>(_progressBarRenderer)->setTextureRect(Rect(x, y, _progressBarTextureSize.width * (percent/100.0f), _progressBarTextureSize.height));
Sprite* spriteRenderer = static_cast<Sprite*>(_progressBarRenderer);
Rect rect = spriteRenderer->getTextureRect();
rect.size.width = _progressBarTextureSize.width * res;
spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.size);
}
}