fix loadingbar direction changed error

This commit is contained in:
Liam 2015-12-19 15:59:27 +08:00
parent b480e9191d
commit 8bf7908e93
3 changed files with 87 additions and 32 deletions

View File

@ -111,26 +111,10 @@ 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)
{
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)
{
auto innerSprite = _barRenderer->getSprite();
if (nullptr != innerSprite)
{
innerSprite->setFlippedX(true);
}
}
break;
}
@ -183,25 +167,9 @@ void LoadingBar::setupTexture()
{
case Direction::LEFT:
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
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)
{
auto innerSprite = _barRenderer->getSprite();
if (nullptr != innerSprite)
{
innerSprite->setFlippedX(true);
}
}
break;
}
_barRenderer->setCapInsets(_capInsets);

View File

@ -12,6 +12,7 @@ UILoadingBarTests::UILoadingBarTests()
ADD_TEST_CASE(UILoadingBarTest_Scale9_State_Change);
ADD_TEST_CASE(UILoadingBarReloadTexture);
ADD_TEST_CASE(UILoadingBarIssue12249);
ADD_TEST_CASE(UILoadingBarTest_Direction);
}
// UILoadingBarTest_Left
@ -510,3 +511,76 @@ void UILoadingBarIssue12249::update(float delta)
loadingBar->setPercent(_count);
loadingBarCopy->setPercent(_count);
}
// UILoadingBarTest_Direction
UILoadingBarTest_Direction::UILoadingBarTest_Direction()
: _count(0)
{
}
UILoadingBarTest_Direction::~UILoadingBarTest_Direction()
{
//unscheduleUpdate();
}
bool UILoadingBarTest_Direction::init()
{
if (UIScene::init())
{
//scheduleUpdate();
Size widgetSize = _widget->getContentSize();
// Add the alert
Text* alert = Text::create("Test LoadingBar Change Direction",
"fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the loading bar
LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
loadingBar->setTag(0);
loadingBar->setPercent(80);
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
auto loadingBarCopy = (LoadingBar*)loadingBar->clone();
loadingBarCopy->setTag(1);
loadingBarCopy->setPosition(loadingBar->getPosition()
+ Vec2(0, -40));
loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
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([=](Ref*, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
if (loadingBar->getDirection() == LoadingBar::Direction::LEFT)
{
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
loadingBarCopy->setDirection(LoadingBar::Direction::LEFT);
}
else
{
loadingBar->setDirection(LoadingBar::Direction::LEFT);
loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
}
}
});
_uiLayer->addChild(loadingBar, 1);
_uiLayer->addChild(loadingBarCopy, 2);
_uiLayer->addChild(button);
_loadingBar = loadingBar;
return true;
}
return false;
}

View File

@ -129,4 +129,17 @@ protected:
int _count;
};
class UILoadingBarTest_Direction : public UIScene
{
public:
CREATE_FUNC(UILoadingBarTest_Direction);
UILoadingBarTest_Direction();
~UILoadingBarTest_Direction();
virtual bool init() override;
protected:
int _count;
cocos2d::ui::LoadingBar* _loadingBar;
};
#endif /* defined(__TestCpp__UILoadingBarTest__) */