Creating loading bars
When you are consuming a process or downloading something, you can indicate that it is not frozen by showing its progress to the user. To show such progresses, Cocos2d-x has a LoadingBar
class. In this recipe, you will learn how to create and show the loading bars.
Getting ready
Firstly, we have to prepare an image for the progress bar. This image is called loadingbar.png
. You will add this image in the Resouces/res
folder.
How to do it...
It generates an instance of the loading bar by specifying the image of the loading bar. Further, it is set to 0% by using the setPercent
method. Finally, in order to advance the bar from 0% to 100% by 1% at 0.1 s, we will use the schedule
method as follows:
auto loadingbar = ui::LoadingBar::create("res/loadingbar.png"); loadingbar->setPosition(size/2); loadingbar->setPercent(0); this->addChild(loadingbar); this->schedule([=](float delta){ float percent = loadingbar->getPercent(); percent++; loadingbar->setPercent...