cocos2d-x 进度条的实现

cocos2d-x的进度条函数CCProgressTimer,我们可以这样定义:

     CCProgressTimer *left = CCProgressTimer::create(CCSprite::create(s_pPathSister1));//s_pPathSister1为图片的路径

然后我们设置进度条的属性:

    left->setType(kCCProgressTimerTypeBar);//kCCProgressTimerTypeBar为进度条的形式

cocos2d-x封装了2中显示方式:

    条形:kCCProgressTimerTypeBar

    圆弧形:kCCProgressTimerTypeRadial

还有很重要的属性:setMidpoint()  //设置中心点,对圆弧来说,就是中心点,但对条形来说,中心点不是条形的中心

// 它是一个表示动画方向的成员变量值,如果是横向方向,则设为(1,0),如果是纵向方向,则设为(0,1); 

下面是两种情况的例子

圆弧进度条:

    CCSprite* sprite = CCSprite::create("test2.png");

    CCProgressTimer* jdt = CCProgressTimer::create(sprite);
     jdt->setType(kCCProgressTimerTypeRadial);
     //jdt->setBarChangeRate(ccp(1, 0));
     //jdt->setMidpoint(ccp(0,0));
    jdt->setPosition(ccp(524,348));
    this->addChild(jdt);

    CCProgressTo* action1 = CCProgressTo::create(20, 100);
    jdt->runAction(CCRepeatForever::create(action1));

 

条形进度条:

    CCSprite* sprite = CCSprite::create("test2.png");

    CCProgressTimer* jdt = CCProgressTimer::create(sprite);
     jdt->setType(kCCProgressTimerTypeBar);
     jdt->setBarChangeRate(ccp(1, 0));
     jdt->setMidpoint(ccp(0,0));
    jdt->setPosition(ccp(524,348));
    this->addChild(jdt);

    CCProgressTo* action1 = CCProgressTo::create(20, 100);
    jdt->runAction(CCRepeatForever::create(action1));

 

 

 

你可能感兴趣的:(cocos2dx)