IOS_31_cocos2d_Progress progress bar and cocos2d progress bar

Source: Internet
Author: User
Tags radar

IOS_31_cocos2d_Progress progress bar and cocos2d progress bar
Finally:
Progress bar node [CCProgressNode],The constructor depends on a Sprite.IsCCProgressNode] AddCCActionProgressFromToAction
You can also change the CCProgressNode in the update method.The percentage attribute of to achieve the progress bar effect.
CCProgressNode]Basic attributes:
CCProgressNode] Constructor:

There are only two types:Radar and bar
Progress bar scenario code

/// ProgressScene. h // 31_cocos2D getting started /// Created by beyond on 14-9-22. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "CCScene. h "# import" cocos2d. h "# import" cocos2d-ui.h "@ interface ProgressScene: CCScene + (instancetype) scene;-(id) init; @ end


/// ProgressScene. m // 31_cocos2D getting started /// Created by beyond on 14-9-22. // Copyright (c) 2014 com. beyond. all rights reserved. // demo progress bar: radar or bar # import "ProgressScene. h "@ interface ProgressScene () {// genie CCSprite * _ sprite; // equivalent to a ProgressView. A Sprite is displayed in the form of progress. (according to the instructions, the constructor is used, sprite required) CCProgressNode * _ progressNode;} @ end @ implementation ProgressScene # pragma mark-lifecycle + (instancetype) scene {return [se Lf alloc] init];}-(id) init {self = [super init]; if (! Self) return (nil); // 1. create a dark gray background color [self setupBgColor]; // 2. add a button to return to the main scenario, in the upper-right corner of [self addBackToMainBtnOnRightTop]; // 3. click the Add demo button to display different progress results [self addShowBtns]; // return the created scenario object return self;} // 3. click the Add demo button to display different progress results-(void) addShowBtns {// 1. create a sprite and do not add it to self _ sprite = [CCSprite spriteWithImageNamed: @ "nanaLogo.jpg"]; _ sprite. name = @ "nana"; // 2. it is equivalent to a ProgressView. A Sprite is displayed in the form of progress. (According to the description, the construction method of Spri is required. Te) _ progressNode = [CCProgressNode progressWithSprite: _ sprite]; // you must also set the position _ progressNode. position = ccp (self. contentSize. width * 0.5, self. contentSize. height/2); // 3. radar [self addBtn: @ "[radar]" position: ccp (0, 0) target: self sel: @ selector (radarBtnClick)]; // 4.bar [self addBtn: @ "[bar]" position: ccp (0, 0.2) target: self sel: @ selector (barBtnClick)]; // 5. label [self addBtn: @ "[Label]" position: ccp (0, 0.4) t Arget: self sel: @ selector (labelBtnClick)] ;}# click The pragma mark-button // 1. click the button to demonstrate [radar progress bar]-(void) radarBtnClick {[_ progressNode removeFromParent]; // The radar progress bar _ progressNode is set to the following type. type = CCProgressNodeTypeRadial; // value range: 0 ~ 100 0 indicates that no _ progressNode is displayed. percentage = 0; // radar center point, similar to the anch_progressnode. midpoint = ccp (0.5, 0.5); // 2. add to self [self addChild: _ progressNode]; // 3. you can execute an action to increase the progress bar, or you can use the/CCActionProgressFromTo * action = [CCActionProgressFromTo actionWithDuration: 1 from: 0 to: 100] In the message Scheduling update method. // [_ progressNode runAction: action];} // 2. click the button to demonstrate [bar progress bar]-(void) barBtnClick {[_ progressNode removeFromParent]; // set the type: Bar progress bar _ progressNode. type = CCProgressNodeTypeBar; // range: 0 ~ 100 0 indicates that no _ progressNode is displayed. percentage = 0; // The center of the bar, similar to the anchor, which is set to _ progressNode from the lower left corner. midpoint = ccp (0.0, 0.0); // barChangeRate, which is a point. It is valid only in bar conditions and only increases in X direction, but not in Y direction. barChangeRate = ccp (1.0, 0.0); // Note: when the value of y in barChangeRate is 0, the Y direction is not increased. Therefore, y of the midpoint can be written at will. // 2. add to self [self addChild: _ progressNode]; // 3. you can execute an action to increase the progress bar or use the message Scheduling update method to // CCActionProgressFromTo * action = [CCActionProgressFr OmTo actionWithDuration: 1 from: 0 to: 100]; // [_ progressNode runAction: action];} // 2. click the button to demonstrate [Label progress bar]-(void) labelBtnClick {[_ progressNode removeFromParent]; // default cocos2d Font: Marker Felt // 1. first, display a white CCLabelTTF * bgWhiteLabel = [CCLabelTTF labelWithString: @ "Loading... "fontName: @" Marker Felt "fontSize: 60]; bgWhiteLabel. position = ccp (self. contentSize. width * 0.5, self. contentSize. height/2); [self addC Hild: bgWhiteLabel]; // 2. create a red one, but it is not displayed at the beginning. The progress is 0 CCLabelTTF * redLabel = [CCLabelTTF labelWithString: @ "Loading... "fontName: @" Marker Felt "fontSize: 60]; redLabel. color = [CCColor colorWithCcColor3b: ccc3 (255, 0, 0)]; _ progressNode = [CCProgressNode progressWithSprite: redLabel]; _ progressNode. position = bgWhiteLabel. position; // The setting type is bar progress bar _ progressNode. type = CCProgressNodeTypeBar; // value range: 0 ~ 100 0 indicates that no _ progressNode is displayed. percentage = 0; // The center of the bar, similar to the anchor, which is set to _ progressNode from the lower left corner. midpoint = ccp (0.0, 0.0); // barChangeRate, which is a point. It is valid only in bar conditions and only increases in X direction, but not in Y direction. barChangeRate = ccp (1.0, 0.0); // Note: when the value of y in barChangeRate is 0, the Y direction is not increased. Therefore, y of the midpoint can be written at will. // 2. add to self [self addChild: _ progressNode] ;}# pragma mark-message scheduling // cocos2d V3. As long as the update method is implemented, it will automatically call // Therefore, you can also use message scheduling to add a progress bar-(void) update :( CCTime) delta {_ progressNode. percentage ++ ;}# pragma mark-extract // Add a button-(void) addBtn :( NSString *) title position :( CGPoint) position target :( id) target sel :( SEL) sel {// create a button and click it to enter the next scenario CCButton * btn = [CCButton buttonWithTitle: title fontName: @ "Verdana-Bold" fontSize: 18366f]; btn. positionType = CCPositionTypeNormalized; // For example, the ccp (0.5f, 0.35f) is located in the center of the screen. // note that the Cartesian coordinate system is used, and the origin is in the lower left btn. position = position; btn. anchorPoint = ccp (0, 0); // listens for click events [btn setTarget: target selector: sel]; [self addChild: btn];} # pragma mark-fixed syntax // fixed syntax: in the upper right corner, create a return button and click it to return to the main scenario-(void) addBackToMainBtnOnRightTop {// 5. In the upper right corner, create a return button and click it to return to the Main scenario CCButton * backButton = [CCButton buttonWithTitle: @ "[back to Main]" fontName: @ "Verdana-Bold" fontSize: 18366f]; backButton. positionType = CCPositionTypeNormalized; // in the upper-right corner of the screen, note that the Cartesian coordinate system is used. The origin is in the backButton at the lower-left corner. position = ccp (0.85f, 0.95f); // listen to the click event [backButton setTarget: self selector: @ selector (backToMainBtnClicked)]; [self addChild: backButton];} // fixed syntax: return to the main scenario-(void) backToMainBtnClicked {// use the transition animation to switch the scene to the main scenario. Animation: from left to right [[CCDirector shareddire] replaceScene: [NSClassFromString (@ "MainScene") scene] withTransition: [CCTransition failed: CCTransitionDirectionRight duration: 1.0f];} // fixed method: Create a background color in dark gray-(void) setupBgColor {CCNodeColor * background = [CCNodeColor nodeWithColor: [CCColor colorWithRed: 0.2f green: 0.2f blue: 0.2f alpha: 1.0f]; [self addChild: background];} @ end













What is the role of the progress bar of the cocos2d-x, what is the need to load the progress bar, there are specific examples,

The progress bar is used in many places. First, you can view the game progress and the unit's blood volume and magic volume. If this attribute can be quantified, you can use the progress bar to display the progress, progress bars are often used in game development.
Of course, you can download network resources, loading progress of program initialization, and so on.
There are many examples of initialization Methods online,
CCProgressTo * p1 = CCProgressTo: actionWithDuration (2,80 );
CCProgressTimer * pt = CCProgressTimer: progressWithFile ("radial.png ");
Pt-> setType (kCCProgressTimerTypeRadialCW );
AddChild (pt );
Pt-> setPosition (ccp (size. width/2, size. height/2 ));
Pt-> runAction (CCRepeatForever: actionWithAction (p1 ));

How to Implement progress bar using C language

CreateWindow (PROGRESS_CLASS, NULL, WS_VISIBLE | WS_CHILD | PBS_SMOOTH, 20,370,370, 30, hwnd, (HMENU) 200, (LPCREATESTRUCT) lParam)-> hInstance, NULL );

Related Messages
PBM_GETPOS: Get the current location
PBM_SETPOS: sets the current position and points to this position.
PBM_GETRANG to get the progress bar range
PBM_SETRANG
PBM_SETRANG32: Set the progress bar range
PBM_SETSTEP: Set the Step Length
PBM_STEPIT execution step

For details, see MSDN.

C language is basically WIN32 SDK.

Related Article

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.