Hi,
I’m trying to use the feature ui::LoadingBar
that cocos2d provides. But I’ve problems with scheduleOnce
method.
This is my code:
auto continueBar = ui::LoadingBar::create("continue.png");
continueBar->setName("continueBar");
continueBar->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2));
continueBar->setDirection(ui::LoadingBar::Direction::RIGHT);
continueBar->setPercent(100);
GameManager::getInstance()->getScene()->addChild(continueBar);
continueBar->scheduleOnce(SEL_SCHEDULE(&Game::continueBar), 0.2);
Method:
void Game::continueBar()
{
auto continueBar = (ui::LoadingBar*)GameManager::getInstance()->getScene()->getChildByName("continueBar");
int porc = continueBar->getPercent();
if(porc > 0)
{
continueBar->setPercent(porc-1);
continueBar->scheduleOnce(SEL_SCHEDULE(&Game::continueBar), 0.2);
}
}
I would like to show 100% of the loadingBar and decrease it to 0% at the end. In other words, at the end I would like to hide the loading bar image.
When I run it, I view 100% of image and the method continueBar
never is called.
I’m doing something wrong? Or it’s a bug?
Thanks.