Loading Bar issues

Loading Bar issues
0

#1

getPercent() from LoadingBar always seems to return 0 even straight after I set it to 100. This is my code below:

bar = LoadingBar::create("loading.png");
bar->setDirection(LoadingBar::Direction::LEFT);
bar->setPosition(visibleSize/2);
this->addChild(bar);
bar->setPercent(100);
CCLOG("Percent: %i", bar->getPercent()); //Logs 0

Any help would be appreciated.


#2

Have you tried stepping through the code in a debugger? It will help you figure it out very quickly.


#3

Try %d instead of %i


#4

I created a new project and used %d and it still logged 0.
Logging directly from cocos2d\cocos\ui\UILoadingBar.cpp still logs 0 no matter what percentage I set it at. However, the image does display as intended (i.e 50 displays half the image).
@slackmoehrle Could this be a bug?


#6

You need to use %f instead of %d or %i to display float values.

I actually got an error in XCode about wrong format specifier, not sure which compiler you’re using, but may want to look into how to enable that error for the future.