Ios_31_cocos2d_progress progress bar

Source: Internet
Author: User

Final:
progress bar Node "Ccprogressnode", dependent on a sprite during construction Add a for "Ccprogressnode" Ccactionprogressfromto Action
You can also changethe percentage property of "Ccprogressnode" in the Update method toachieve a progress bar effect
"Ccprogressnode" Basic properties:
"Ccprogressnode" Construction method:

There are only two types of it: Radar and Bars
progress bar Scenario Code
  progressscene.h//  31_cocos2d Primer////  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 Primer////Created by Beyond on 14-9-22.//Copyright (c) 2014 Com.beyond. All Rights reserved.//Demo progress bar: Radar or bar bar #import "ProgressScene.h" @interface Progressscene () {//Elf Ccsprite *_sprite        ; Equivalent to a progressview, through the form of progress, showing a sprite, (according to the instructions, its construction method, requires a sprite) Ccprogressnode *_progressnode;} @end @implementation Progressscene#pragma Mark-life cycle + (instancetype) Scene{return [[Self alloc] init];}    -(ID) init{self = [super init];        if (!self) return (nil);        1. Create a dark gray background color [self setupbgcolor];                2. Add a button that returns to the main scene in the upper right [self addbacktomainbtnonrighttop];        3. Add Demo button, click to show different progress effect [self addshowbtns]; Returns the created scene object return self; 3. Add Demo button, click to show different progress effect-(void) addshowbtns{//1. Create an elf, not add to self _sprite = [Ccsprite spritewithimagenamed:@ "nanal    Ogo.jpg "];    _sprite.name = @ "Nana"; 2. Equivalent to a progressview, through the form of progress, showing a sprite, (according to the instructions, its construction method, requires a sprite) _progressnode = [Ccprogressnode progresswithspriTe:_sprite];                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) target:self sel: @selector (Labelbtnclick)];}        #pragma mark-button click//1. Click on the button to demonstrate "radar progress bar"-(void) radarbtnclick{[_progressnode removefromparent];    The setting type is: Radar progress bar _progressnode.type = ccprogressnodetyperadial;        Range: 0 ~ 100 0 means nothing shows _progressnode.percentage = 0;        The center point of the radar, similar to the anchor point _progressnode.midpoint = CCP (0.5,0.5);        2. Add to self [self addchild:_progressnode]; 3. The progress bar can be increased by executing the action, or by the message dispatch Update method//Ccactionprogressfromto *action = [Ccactionprogressfromto Actionwithduration:1 from:0 to:100];//[_progressnode runaction:action];} 2. Click the button to show "Bar Progress Bar"-(void) Barbtnclick{[_progressnode removefromparent];    The setting type is: Bar progress bar _progressnode.type = Ccprogressnodetypebar;        Range: 0 ~ 100 0 means nothing shows _progressnode.percentage = 0;        The center point of the bar, similar to the anchor point, is set from the lower left corner _progressnode.midpoint = CCP (0.0,0.0);        Barchangerate, is a point that only works in the bar condition, only increases in the X direction, does not increase in the y direction _progressnode.barchangerate = CCP (1.0,0.0);        Note: When Y is 0 o'clock in barchangerate, the y direction does not increase, so midpoint y can be written casually//2. Add to self [self addchild:_progressnode]; 3. The progress bar can be increased by executing the action, or by the message dispatch Update method//Ccactionprogressfromto *action = [Ccactionprogressfromto Actionwithdura    Tion:1 from:0 to:100]; [_progressnode runaction:action];}    2. Click the button to show "label Progress Bar"-(void) labelbtnclick{[_progressnode removefromparent]; cocos2d default font: Marker Felt//1. First show a white cclabelttf *bgwhitelabel = [Cclabelttf labelwithstring:@ "Loading ..." Fontna    me:@ "Marker Felt" fontsize:60];    Bgwhitelabel.position = CCP (SELF.CONTENTSIZE.WIDTH*0.5,SELF.CONTENTSIZE.HEIGHT/2); [Self ADdchild:bgwhitelabel]; 2. Create a red one, but do not show at first, progress is 0 cclabelttf *redlabel = [Cclabelttf labelwithstring:@ "Loading ..." fontname:@ "Marker Felt" fon    TSIZE: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;        Range: 0 ~ 100 0 means nothing shows _progressnode.percentage = 0;        The center point of the bar, similar to the anchor point, is set from the lower left corner _progressnode.midpoint = CCP (0.0,0.0);        Barchangerate, is a point that only works in the bar condition, only increases in the X direction, does not increase in the y direction _progressnode.barchangerate = CCP (1.0,0.0);        Note: When Y is 0 o'clock in barchangerate, the y direction does not increase, so midpoint y can be written casually//2. Add to self [self addchild:_progressnode]; } #pragma mark-in the message dispatch//Cocos2d V3, as long as the Update method is implemented, it is automatically called///and therefore can also be implemented via message scheduling to increase the progress bar-(void) Update: (cctime) delta{_progress node.percentage++;} #pragma mark-extract//Add a button-(void) ADDBTN: (NSString *) title position: (CgpointPosition target: (ID) Target sel: (SEL) sel{//Create a button, click to enter next scene Ccbutton *btn = [Ccbutton buttonwithtitle:title fontn    ame:@ "Verdana-bold" fontsize:18.0f];    Btn.positiontype = ccpositiontypenormalized;    For example: CCP (0.5f, 0.35f) is located in the middle of the screen bottom//Note here is the Cartesian coordinate system, the origin in the lower left btn.position = position;    Btn.anchorpoint = CCP (0, 0);    Monitor click events [BTN settarget:target Selector:sel]; [Self addchild:btn];} #pragma mark-fixed/fixed: top right, create a Back button, click to return to main scene-(void) addbacktomainbtnonrighttop{//5, top right, create a Back button, click to return to main scene C    CButton *backbutton = [Ccbutton buttonwithtitle:@ "[Back to main]" fontname:@ "Verdana-bold" fontsize:18.0f ";    Backbutton.positiontype = ccpositiontypenormalized;    On the top right of the screen note here is the Cartesian coordinate system, the origin at the lower left backbutton.position = CCP (0.85f, 0.95f);    Listen for click events [Backbutton settarget:self selector: @selector (backtomainbtnclicked)]; [Self Addchild:backbutton];} Fixed notation: Return to main scene-(void) backtomainbtnclicked{//Use transition animation, toggle scene to main scene, animation: left to right [[Ccdirector Shareddirector] Replacescene: [Nsclassfromstring (@ "Mainscene") scene] Withtransition:[cctransition Transitionpushwithdire Ction:cctransitiondirectionright duration:1.0f]];} Fixed method: Create a background color of 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












Ios_31_cocos2d_progress progress bar

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.