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; }
bool UILoadingBarTest_Left::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->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; TTFConfig ttfConfig("fonts/arial.ttf", 15); auto label1 = Label::createWithTTF(ttfConfig, "Print Resources"); auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UILoadingBarTest_Left::printWidgetResources, this)); item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3)); auto pMenu1 = Menu::create(item1, nullptr); pMenu1->setPosition(Vec2(0, 0)); this->addChild(pMenu1, 10); return true; } return false; }