A simple Demo of a circular progress bar for COCOS2D-X

Source: Internet
Author: User

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 }}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.