Restarting progressbar

Hi Guys,

I have created a ProgressTimer and set the type as Radial. The problem is that, sometimes I needs to restart the progress timer before it completes. If I do so, the progress complete call back function is calling before it really completes. Anybody knows about it, here is the code

version: (Cocos2dx 3.2 CPP)

void CustomProgressTimer::restart(){
stopTimer();
startTimer();
}
void CustomProgressTimer::startTimer(){    
   progressTimer->setPercentage(0);    
    auto actionInterval=ProgressFromTo::create(TIMER_LENGTH, 100, 0);    
    CallFuncN*  callbackFunction=CallFuncN::create(CC_CALLBACK_1(CustomProgressTimer::timerExpired,this));   
    auto seq=Sequence::create(actionInterval,callbackFunction, NULL);    
    progressTimer->runAction(seq);
}
void CustomProgressTimer::stopTimer(){
    progressTimer->stopAllActions();        
    progressTimer->setPercentage(0);
}

Thanks a lot

I don’t know how it could happen that :

Just try giving a little delay of say 0.5 seconds before the callback function in the seq definition.

Anyways, how come you know whether it is calling callback before completing the progress bar…
I think 2 possibilities are there which can make you think so,

  1. It is showing resources not found after the callback is called, in which case, it is really getting called before progress bar completion
  2. You might not be seeing the last delta of the progress bar because since there is not delay between progress bar action and callback function, so it might be immediately doing callback as soon as it is doing 100% progress bar completion where you might not see the last delta.
    By delta, I mean that suppose your 98 % resources are loaded and hence your progress bar is showing 98% but
    the last 2 % progress you might not see because it is immediately calling callback once the progress is completed…

See, I am not very sure but this is my interpretation if you’re really sure that it seems that callback is being called before its preceding action!!

Just try giving delay… or lets wait for more answers :stuck_out_tongue:

I’m really sorry for your time,
I double checked and Identified the problem, it was completely my mistake, I used to get a callback call before stoptimer is getting called.Because of a logical error, it was not triggering the callback.

Thanks a lot

pls help to code for progress bar level running wich i already created in cocos2dx