diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index a1197e30ee..c4bd289b82 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -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); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 6eff4c32bb..d35da4c331 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -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;