mirror of https://github.com/axmolengine/axmol.git
fix loadingbar direction changed error
This commit is contained in:
parent
b480e9191d
commit
8bf7908e93
|
@ -111,26 +111,10 @@ void LoadingBar::setDirection(cocos2d::ui::LoadingBar::Direction direction)
|
||||||
case Direction::LEFT:
|
case Direction::LEFT:
|
||||||
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
|
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
|
||||||
_barRenderer->setPosition(Vec2(0,_contentSize.height*0.5f));
|
_barRenderer->setPosition(Vec2(0,_contentSize.height*0.5f));
|
||||||
if (!_scale9Enabled)
|
|
||||||
{
|
|
||||||
auto innerSprite = _barRenderer->getSprite();
|
|
||||||
if (nullptr != innerSprite)
|
|
||||||
{
|
|
||||||
innerSprite->setFlippedX(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Direction::RIGHT:
|
case Direction::RIGHT:
|
||||||
_barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
|
_barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
|
||||||
_barRenderer->setPosition(Vec2(_totalLength,_contentSize.height*0.5f));
|
_barRenderer->setPosition(Vec2(_totalLength,_contentSize.height*0.5f));
|
||||||
if (!_scale9Enabled)
|
|
||||||
{
|
|
||||||
auto innerSprite = _barRenderer->getSprite();
|
|
||||||
if (nullptr != innerSprite)
|
|
||||||
{
|
|
||||||
innerSprite->setFlippedX(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,25 +167,9 @@ void LoadingBar::setupTexture()
|
||||||
{
|
{
|
||||||
case Direction::LEFT:
|
case Direction::LEFT:
|
||||||
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
|
_barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
|
||||||
if (!_scale9Enabled)
|
|
||||||
{
|
|
||||||
auto innerSprite = _barRenderer->getSprite();
|
|
||||||
if (nullptr != innerSprite)
|
|
||||||
{
|
|
||||||
innerSprite->setFlippedX(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Direction::RIGHT:
|
case Direction::RIGHT:
|
||||||
_barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
|
_barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
|
||||||
if (!_scale9Enabled)
|
|
||||||
{
|
|
||||||
auto innerSprite = _barRenderer->getSprite();
|
|
||||||
if (nullptr != innerSprite)
|
|
||||||
{
|
|
||||||
innerSprite->setFlippedX(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_barRenderer->setCapInsets(_capInsets);
|
_barRenderer->setCapInsets(_capInsets);
|
||||||
|
|
|
@ -12,6 +12,7 @@ UILoadingBarTests::UILoadingBarTests()
|
||||||
ADD_TEST_CASE(UILoadingBarTest_Scale9_State_Change);
|
ADD_TEST_CASE(UILoadingBarTest_Scale9_State_Change);
|
||||||
ADD_TEST_CASE(UILoadingBarReloadTexture);
|
ADD_TEST_CASE(UILoadingBarReloadTexture);
|
||||||
ADD_TEST_CASE(UILoadingBarIssue12249);
|
ADD_TEST_CASE(UILoadingBarIssue12249);
|
||||||
|
ADD_TEST_CASE(UILoadingBarTest_Direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UILoadingBarTest_Left
|
// UILoadingBarTest_Left
|
||||||
|
@ -510,3 +511,76 @@ void UILoadingBarIssue12249::update(float delta)
|
||||||
loadingBar->setPercent(_count);
|
loadingBar->setPercent(_count);
|
||||||
loadingBarCopy->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;
|
||||||
|
}
|
|
@ -129,4 +129,17 @@ protected:
|
||||||
int _count;
|
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__) */
|
#endif /* defined(__TestCpp__UILoadingBarTest__) */
|
||||||
|
|
Loading…
Reference in New Issue