cocos2d-x提供了CCProgressTimer类,可以方便地实现进度条的功能,从cocos2d-x 2.x版本以后将ProgressTimer的类型减少为两种:
typedef enum { /// Radial Counter-Clockwise kCCProgressTimerTypeRadial, /// Bar kCCProgressTimerTypeBar, } CCProgressTimerType;
m_pSpeedBG = CCSprite::create("BG.png");
m_pSpeedBG->setPosition(ccp(mScreenSize.width * 0.5f, 494));m_pConfigureNode->addChild(m_pSpeedBG);
m_pMenuSpeed = CCProgressTimer::create(CCSprite::create("Top.png"));
m_pMenuSpeed->setType(kCCProgressTimerTypeBar);// 设置进度条的类型为条形
m_pMenuSpeed->setMidpoint(ccp(0,0.5));// 设置开始展示点的位置,动画开始的起始点
m_pMenuSpeed->setAnchorPoint(ccp(0.0f,0.5f));
m_pMenuSpeed->setBarChangeRate(ccp(1, 0));// 设置进度条变化方向
m_pMenuSpeed->setPosition(ccp(0,m_pMenuSpeed->getContentSize().height * 0.5f));
m_pMenuSpeed->setPercentage(m_nSpeedPoint * 5);// 设置初始百分比的值
m_pSpeedBG->addChild(m_pMenuSpeed);
图Top.png
参考: