This should be a common effect in games. displays the progress of an event, which is often used when resources are loaded or connected to the Internet. so it is necessary to learn first, we directly in the COCOS2D-X built-in HelloCpp project to add code. add the following code in Initialization:
CCSprite * pSprite = CCSprite: create ("A.png"); // For the moment, it is a blue background. CCSize szWin = CCDirector: sharedDirector ()-> getVisibleSize (); pSprite-> setPosition (CCPointMake (szWin. width/2, szWin. height/2); this-> addChild (pSprite); CCProgressTimer * pProgressTimer = CCProgressTimer: create (CCSprite: create ("B .png ")); // red circle progress bar pProgressTimer-> setPosition (CCPointMake (szWin. width/2, szWin. height/2); pProgressTimer-> setPercentage (0); // display the percentage of the original shape. this-> addChild (pProgressTimer, 0,100); this-> schedule (schedule_selector (HelloWorld :: updateProgress); // update the progress based on actual conditions. the timer is used for demonstration.
2. Then we need to implement the function called by the timer. The Code is as follows and attached.
Void HelloWorld: UpdateProgress (float Dt) {CCProgressTimer * pProgressTimer = (CCProgressTimer *) this-> progress (100); pProgressTimer-> setPercentage (pprogresstage> getPercentage () + Dt * 10); // update progress if (pProgressTimer-> getPercentage () = 100) {this-> unschedule (schedule_selector (HelloWorld: UpdateProgress )); // cancel the timer }}