Ejemplo n.º 1
0
void ProgressBar::progressBy(float delta)
{
    float maxPercentage = 100.0f;

    bool isFinished = false;
    float nextPercentage = delta + this->getPercentage();
    if(nextPercentage >= maxPercentage){
        nextPercentage = maxPercentage;
        isFinished = true;
    }
    this->stopActionByTag(k_Progress_Action);
    CCArray *actions = CCArray::createWithCapacity(2);
    float duration = delta/this->getSpeed();
    CCProgressTo* to = CCProgressTo::create(duration, nextPercentage);
    actions->addObject(to);
    if(isFinished){
        CCCallFunc* callfunc = CCCallFunc::create(this, callfunc_selector(ProgressBar::loadingFinished));
        actions->addObject(callfunc);
    }
    CCFiniteTimeAction* seq = CCSequence::create(actions);
    
    CCCallFunc* updatePercentage = CCCallFunc::create(this, callfunc_selector(ProgressBar::updatePercentage));
    updatePercentage->setDuration(duration);

    CCSpawn* spawn = CCSpawn::createWithTwoActions(seq, updatePercentage);
    spawn->setTag(k_Progress_Action);
    
    this->runAction(spawn);
}