Loading Bar issues

Loading Bar issues


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");
CCLOG("Percent: %i", bar->getPercent()); //Logs 0

Any help would be appreciated.


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


Try %d instead of %i


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?


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.