收集整理的两个进度条效果,第一个常用于技能冷却,第二个用于加载进度或血量之类
bool HelloWorld::init(){ if ( !CCLayer::init() ) { return false; } CCSprite *s2=CCSprite::create("pa2.png"); s2->setPosition(ccp(200,200)); addChild(s2,0); CCSprite *s=CCSprite::create("pa1.png"); CCProgressTimer *pt=CCProgressTimer::create(s); pt->setPosition(ccp(200,200)); //转圈的CD实现 pt->setType(cocos2d::CCProgressTimerType(kCCProgressTimerTypeRadial)); //从中间到外的出现 this->addChild(pt,1); CCProgressTo *t=CCProgressTo::create(8,100); pt->runAction(CCRepeatForever::create(t)); CCSize size = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); // 设置进度条的背景图片 我们把他放到屏幕下方的1/5处 CCSprite* loadbackimg=CCSprite::create("lodingbg.png"); loadbackimg->setPosition(ccp(size.width/2 + origin.x,size.height/5 + origin.y)); this->addChild(loadbackimg,1); // 添加进度条 CCSprite* loadimg=CCSprite::create("longding.png"); CCProgressTimer* pt2 = CCProgressTimer::create(loadimg); pt2->setType(kCCProgressTimerTypeBar);// 设置成横向的 //可以看作是按矩形显示效果的进度条类型 pt2->setMidpoint(ccp(0,1)); // 设置进度方向 pt2->setBarChangeRate(ccp(0,1)); // 设置进度为水平还是垂直方向 //重新设置锚点 pt2->setPosition(ccp(size.width/2 + origin.x,size.height/5 + origin.y-5)); pt2->setPercentage(10); this->addChild(pt2,2,1); //为该层设置定时器 this->scheduleUpdate(); return true;}void HelloWorld::update(float dt) { // 刷新进度 CCProgressTimer* pt=(CCProgressTimer*)this->getChildByTag(1); float now=pt->getPercentage(); if(now == 100){ now = 0; } pt->setPercentage(now + 1);}