cocos2dx进度条样式设置

转载自:http://blog.csdn.net/junhua_peng/article/details/17008533


1.创建:

CCProgresstime::create("精灵对象");


2.种类:

cocos2dx中,有2种计时器的样式:

[1].kCCProgressTimerTypeRadial:扇形进度计时器

[2].kCCProgressTimerTypeBar:条形进度计时器


3.函数:

setType();                //设置进度条样式

[扇形][1].setPercentage();                  //设置进度值(0-100)

[扇形][2].setReverseProgress();        //设置反向计时(true为开启反向)

[条形][3].setBarChangeRate();          //修改条形计时器变换样式(定义起始样式)

       ccp(1,0):只有X轴变化。          (起始X轴不显示)

       ccp(0,1):只有Y轴变化。          (起始Y轴不显示)

       ccp(1,1):X,Y轴都变化。       (起始X,y轴都不显示)

       ccp(0.5,0.5):X,Y轴都变化 。(起始X,y轴都显示一半)

[条形][4].setMidpoint();                       //设置计时器的显示方式方向,范围(0-1)(默认ccp(0.5,0.5))

       注意:该函数会受到setBarChangeRate函数影响

       当计时条样式为X轴变化时(设置Y轴无效果,这里设为0)

       ccp(1,0):        从右到左显示。

       ccp(0.5,0):     从中间到两边显示。

       ccp(0,0):        从左到右显示

       当计时条样式为Y轴变化时(设置X轴无效果,这里设为0)

       ccp(0,1):        从上到下显示。

       ccp(0,0.5):     从中间到两边显示。

       ccp(0,0):        从下到上显示。

       当计时条样式为X、Y轴都变化时

       ccp(0,1):        X从左到右显示Y从上到下显示

       ccp(0,0.5):     X从中间到两边显示Y从中间到两边显示

       ccp(1,0):        X从右到左显示Y从下到上显示

       ccp(0.5,0):     X从中间到两边显示Y从下到上显示

       ccp(0,0):        X从左到右显示Y从下到上显示

       ccp(0.5,0.5): X从中间到两边显示Y从中间到两边显示

       ccp(1,1):        X从右到左显示Y从上到下显示


3.开始编码

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. 1.包含“cocos-ext.h”文件。#include "cocos-ext.h"  
  2.   
  3. 2.引用命名空间“cocos2d::extension”。using namespace cocos2d::extension;  
  4.   
  5. 3.我们需2个回调函数用于按钮关联事件。  
  6.   
  7. void downaction1(CCObject * sender,CCControlEvent);  
  8.   
  9. void downaction2(CCObject * sender,CCControlEvent);  
  10.   
  11. 4.需2个回调函数用于建造完成关联事件。  
  12.   
  13. void deletesp();  
  14.   
  15. void deletesp2();  
  16.   
  17.   
  18.   
  19. <pre code_snippet_id="86784" snippet_file_name="blog_20131128_1_6597456" name="code" class="cpp">1.引用命名空间“cocos2d::extension”。using namespace cocos2d::extension;  
  20.   
  21. 2.放上背景。  
  22.   
  23.        CCSprite* bgps = CCSprite::create("bg.jpg");  
  24.   
  25.        bgps->setPosition(ccp(mysize.width/2, mysize.height/2));  
  26.   
  27.        this->addChild(bgps, 0);  
  28.   
  29.   
  30.   
  31. 3.创建2个按钮。  
  32.   
  33. CCScale9Sprite * c91=CCScale9Sprite::create("button.png");  
  34.   
  35. CCScale9Sprite * c92=CCScale9Sprite::create("button.png");  
  36.   
  37. CCLabelTTF * ttf1=CCLabelTTF::create("Ji Di","Arial",20);  
  38.   
  39. CCLabelTTF * ttf2=CCLabelTTF::create("Dian Zhan","Arial",20);  
  40.   
  41. CCControlButton * mybutton1=CCControlButton::create(ttf1,c91);  
  42.   
  43. CCControlButton * mybutton2=CCControlButton::create(ttf2,c92);  
  44.   
  45. mybutton1->setPosition(ccp(mysize.width-50,mysize.height-140));  
  46.   
  47. mybutton2->setPosition(ccp(mysize.width-50,mysize.height-180));  
  48.   
  49. mybutton1->setPreferredSize(CCSizeMake(80,30));  
  50.   
  51. mybutton2->setPreferredSize(CCSizeMake(80,30));  
  52.   
  53. this->addChild(mybutton1);  
  54.   
  55. this->addChild(mybutton2);  
  56.   
  57. mybutton1->addTargetWithActionForControlEvents(  
  58.   
  59.    this,  
  60.   
  61.    cccontrol_selector(Progressdemo::downaction1),  
  62.   
  63.    CCControlEventTouchDown  
  64.   
  65. );  
  66.   
  67. mybutton2->addTargetWithActionForControlEvents(  
  68.   
  69.    this,  
  70.   
  71.    cccontrol_selector(Progressdemo::downaction2),  
  72.   
  73.    CCControlEventTouchDown  
  74.   
  75. );  
  76.   
  77. 4.实现按钮回调函数  
  78.   
  79. void Progressdemo::downaction1(CCObject * sender,CCControlEvent){  
  80.   
  81.    //创建扇形进度条  
  82.   
  83.    CCSize mysize=CCDirector::sharedDirector()->getWinSize();  
  84.   
  85.    CCProgressTimer *mypro=CCProgressTimer::create(CCSprite::create("sjd.png"));  
  86.   
  87.    mypro->setPosition(ccp(100,100));  
  88.   
  89.    mypro->setType(kCCProgressTimerTypeRadial);  
  90.   
  91.    mypro->setPercentage(100);  
  92.   
  93.    this->addChild(mypro,100,1);  
  94.   
  95.    //创建计时器  
  96.   
  97.    CCProgressTo * to=CCProgressTo::create(5,100);  
  98.    
  99.   
  100.    CCCallFunc * callback=CCCallFunc::create(this,callfunc_selector(Progressdemo::deletesp));  
  101.   
  102.    CCAction * act=CCSequence::create(to,callback,NULL);  
  103.   
  104.    mypro->runAction(act);  
  105.   
  106. }  
  107.   
  108. void Progressdemo::downaction2(CCObject * sender,CCControlEvent){  
  109.   
  110.    //创建条形进度条  
  111.   
  112.    CCSize mysize=CCDirector::sharedDirector()->getWinSize();  
  113.   
  114.    CCProgressTimer *mypro=CCProgressTimer::create(CCSprite::create("tjd.png"));  
  115.   
  116.    mypro->setPosition(ccp(100,150));  
  117.   
  118.    mypro->setType(kCCProgressTimerTypeBar);  
  119.   
  120.    mypro->setBarChangeRate(ccp(1,0));  
  121.   
  122.    mypro->setMidpoint(ccp(0,1));  
  123.   
  124.    this->addChild(mypro,100,2);  
  125.   
  126.    //创建计时器  
  127.   
  128.    CCProgressTo * to=CCProgressTo::create(3,100);  
  129.   
  130.    //这里为了实现执行完成后再操作需要用到回调函数  
  131.   
  132.    CCCallFunc * callback=CCCallFunc::create(this,callfunc_selector(Progressdemo::deletesp2));  
  133.   
  134.    CCAction * act=CCSequence::create(to,callback,NULL);  
  135.   
  136.    mypro->runAction(act);  
  137.   
  138. }  
  139.   
  140. 5.实现建造回调函数  
  141.   
  142. void Progressdemo::deletesp(){  
  143.   
  144.    CCProgressTimer *mypro=(CCProgressTimer *)this->getChildByTag(1);  
  145.   
  146.    this->removeChild(mypro);  
  147.   
  148.    CCSize mysize=CCDirector::sharedDirector()->getWinSize();  
  149.   
  150.    CCSprite * jidi=CCSprite::create("jd.png");  
  151.   
  152.    jidi->setPosition(ccp(100,100));  
  153.   
  154.    //设置缩放倍数  
  155.   
  156.    jidi->setScale(0.3f);  
  157.   
  158.    this->addChild(jidi);  
  159.   
  160. }  
  161.   
  162. void Progressdemo::deletesp2(){  
  163.   
  164.    CCProgressTimer *mypro=(CCProgressTimer *)this->getChildByTag(2);  
  165.   
  166.    this->removeChild(mypro);  
  167.   
  168.    CCSize mysize=CCDirector::sharedDirector()->getWinSize();  
  169.   
  170.    CCSprite * fdz=CCSprite::create("fdz.png");  
  171.   
  172.    fdz->setPosition(ccp(100,150));  
  173.   
  174.    //设置缩放倍数  
  175.   
  176.    fdz->setScale(0.3f);  
  177.   
  178.    this->addChild(fdz);  
  179.   
  180. }  
  181.   
  182.   
  183.   
  184.   
  185.  </pre><br>  
  186. <pre></pre>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值