Merge pull request #7712 from andyque/testLoadingBar

fixed loadingBar change direction affect position issue
This commit is contained in:
minggo 2014-08-08 11:57:28 +08:00
commit 3ccce066b0
2 changed files with 17 additions and 3 deletions

View File

@ -100,14 +100,14 @@ void LoadingBar::setDirection(cocos2d::ui::LoadingBar::Direction direction)
{
case Direction::LEFT:
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
_barRenderer->setPosition(Vec2(-_totalLength*0.5f,0.0f));
_barRenderer->setPosition(Vec2(0,0.0f));
if (!_scale9Enabled) {
_barRenderer->setFlippedX(false);
}
break;
case Direction::RIGHT:
_barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
_barRenderer->setPosition(Vec2(_totalLength*0.5f,0.0f));
_barRenderer->setPosition(Vec2(_totalLength,0.0f));
if (!_scale9Enabled) {
_barRenderer->setFlippedX(true);
}

View File

@ -35,7 +35,21 @@ bool UILoadingBarTest_Left::init()
loadingBar->setTag(0);
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
Button* button = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
button->setTitleText("Click to change direction!");
// button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent));
button->addTouchEventListener([=](Ref*, Widget::TouchEventType type){
if (type == Widget::TouchEventType::ENDED) {
if (loadingBar->getDirection() == LoadingBar::Direction::LEFT) {
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
}else{
loadingBar->setDirection(LoadingBar::Direction::LEFT);
}
}
});
_uiLayer->addChild(button);
_uiLayer->addChild(loadingBar);
return true;