#include"prograssbar.h"
#include "variable.h"
using namespace cocos2d;
CCScene * prograssbar::scene()
{
CCScene *scene = NULL;
bool bRet =false;
do
{
scene =CCScene::create();
prograssbar* layer =prograssbar::create();
scene->addChild(layer);
bRet =true;
} while (0);
return scene;
}
bool prograssbar::init()
{
CCSize winsize =CCDirector::sharedDirector()->getWinSize();
bool bRet =false;
do{
//创建一个进度条精灵,这个是2.0以后api变了
CCSprite *progressbgSprite=CCSprite::create("prograssbar/lodingbg.png");
progressbgSprite->setPosition(ccp(winsize.width/2.0, winsize.height/2.0));
this->addChild(progressbgSprite, 1);
CCSprite *progressSprite=CCSprite::create("prograssbar/longding.png");
progress1=CCProgressTimer::create(progressSprite);
progress1->setType(kCCProgressTimerTypeBar);
progress1->setPosition(ccp(winsize.width/2.0, winsize.height/2.0));
//进度动画运动方向,可以多试几个值,看看效果
progress1->setMidpoint(ccp(0, 0));
//进度条宽高变化
progress1->setBarChangeRate(ccp(1, 0));
progress1->setPercentage(0);
this->addChild(progress1, 1);
numsTTF=CCLabelTTF::create("0",ID_FONT_FORMAT, ID_FONT_SIZE);
numsTTF->setPosition(ccp(winsize.width/2.0, winsize.height/2.0));
this->addChild(numsTTF, 1);
this->scheduleUpdate();
bRet =true;
}while(0);
return bRet;
}
void prograssbar::update(float dt)
{
float cu=progress1->getPercentage();
if(cu<100)
cu=cu+0.2f;
if(cu<100)
{
progress1->setPercentage(cu);
CCString *str = CCString::createWithFormat("%.2f%%",cu);
numsTTF->setString(str->getCString());
}
}
效果图如下