标签:style blog http io color os ar for sp
1 Bar形进度
CCSprite * proBack = CCSprite::create("barback.png"); proBack->setPosition(ccp(winSize.width/2 - 100,winSize.height/2)); addChild(proBack); CCProgressTimer * left = CCProgressTimer::create(CCSprite::create("bar.png")); left->setPosition(ccp(winSize.width / 2 - 100, winSize.height / 2)); addChild(left); left->setType(kCCProgressTimerTypeBar); left->setMidpoint(ccp(1,0)); left->setBarChangeRate(ccp(1,1)); CCProgressTo * to = CCProgressTo::create(2, 120.0f); left->runAction(CCRepeatForever::create(to)); |
setMidPoint(ccp(x,y));
setMidpoint(ccp(1,0));
x和y均为[0,1]的数值表示进度起始点。比如ccp(0,0)左下角,ccp(1,1)右上角。
setBarChangeRate(ccp(x,y));
x和y均为[0,1]的数值表示,表示水平方向和竖直方向的进度。比如ccp(0,1)表示只有y轴方向有进度。
2 Radial
CCSprite * proBack2 = CCSprite::create("radialback.png"); proBack2->setPosition(ccp(winSize.width / 2 + 100, winSize.height /2)); addChild(proBack2); CCProgressTimer * right = CCProgressTimer::create(CCSprite::create(“radial.png”)); right->setPosition(ccp(winSize.width/2 + 100,winSize.height / 2)); addChild(right); right->setType(kCCProgressTimerTypeRadial); right->setMidpoint(ccp(0.5,0.5)); CCProgressTo * to2 = CCProgressTo::create(2,100.0f); right->runAction(to2); |
3 案例
T17CCProgressTo.h |
#ifndef __T17CCProgressTo_H__ #define __T17CCProgressTo_H__ #include "cocos2d.h" #include "TBack.h"
class T17CCProgressTo :public TBack { public: static CCScene * scene(); CREATE_FUNC(T17CCProgressTo); bool init(); };
#endif |
T17CCProgressTo.cpp |
#include "T17CCProgressTo.h" #include "AppMacros.h" CCScene * T17CCProgressTo::scene() { CCScene * scene = CCScene::create(); T17CCProgressTo * layer = T17CCProgressTo::create(); scene->addChild(layer); return scene; }
bool T17CCProgressTo::init() { TBack::init();
//创建一个CCSprite CCSprite * proBack = CCSprite::create("barback.png"); //设置精灵所在的位置 proBack->setPosition(ccp(winSize.width / 2 - 100, winSize.height / 2)); addChild(proBack);
//创建一个CCProgressTimer作为进度条 CCProgressTimer * left = CCProgressTimer::create(CCSprite::create("bar.png")); //设置进度条所在的位置上。 left->setPosition(ccp(winSize.width / 2 - 100, winSize.height / 2)); //cpp中的 //第一个参数表示的是控制进度条填满的方向, //0表示从左往右运行, //1表示进度条往左边运行 //第二个参数表示上下填满的顺序 //0表示从下往上运行。 //1表示从上往下运行。 //注意:者两个参数的范围都是从0~1 //当中间值设置成为0.5时,进度的显示顺序是从中间开始的 left->setMidpoint(ccp(0, 0.5)); //当设置成1,1的时候上下,左右都能够填满。 left->setBarChangeRate(ccp(0, 1)); //设置类型 left->setType(kCCProgressTimerTypeBar); addChild(left); //动作,表示两秒钟内填满100.0f的值 CCProgressTo * to = CCProgressTo::create(2, 100.0f); //通过下面的方式让这个进度条循环的填充值 left->runAction(CCRepeatForever::create(to));
//创建一个radial的进度条。背景色 CCSprite * proBack2 = CCSprite::create("radialback.png"); //设置radial的显示位置 proBack2->setPosition(ccp(winSize.width / 2 + 100, winSize.height / 2)); addChild(proBack2);
CCProgressTimer * right = CCProgressTimer::create(CCSprite::create("radial.png")); //设置它的显示位置 right->setPosition(ccp(winSize.width / 2 + 100, winSize.height / 2)); //表示它的中心点位置,圆心的位置在圆的正中心 right->setMidpoint(ccp(0.5, 0.5)); right->setType(kCCProgressTimerTypeRadial); addChild(right); //两秒钟内填充100% CCProgressTo * to2 = CCProgressTo::create(2, 100.0f);
right->runAction(CCRepeatForever::create(to2));
return true; } |
运行结果:
|
1.CCProgressTo进度动作,条形进度条,扇形进度条
标签:style blog http io color os ar for sp
原文地址:http://blog.csdn.net/tototuzuoquan/article/details/40593801