@jd
You are right about that. The progress timer doesn't actually measure progress of any specific thing (preloading images, loading game data files, etc).
I couldn't really think of a way to have it measure any of those since everyone has different practices for progression from 0 percent to 100 percent completion so I let users have control of the 'percentage' property instead.
So let's say we load data from file and want the progress timer as a feedback for that load we could do this:
-(void)loadGameDataFromFile:(NSString*)dataFile
{
[self loadWorld:dataFile];
//...
// ok i'm loading stuff right here. I kinda know I've completed 25% of the data
// so let's set that percentage.
//...
progressTimer.percentage = 25.f;
[self loadCharacters:dataFile];
//...
// Characters are now loaded
// so let's set that percentage again.
//...
progressTimer.percentage = 66.f;
[self loadSomeMore:dataFile];
//...
// We've finished loading everything but let's have a more animated loading to 100%
//...
[progressTimer runAction:[CCProgressTo actionWithDuration:25.f percent:100.f]
}
Or maybe we don't know how much we can actually load. So let's just let the timer loop forever and stop it when we are actually done. Following cocos2d's convention of looping actions we do this:
-(void) loadSomeUnknownAmountOfData
{
CCAction *progressLoop = [CCRepeatForever actionWithAction:[ProgressFromTo actionWithDuration:5.f from:0 to:100]];
progressLoop.tag = kProgressLoopTag;
[progressTimer runAction:progressLoop];
// Load async, which will call a function to stop the action when finished.
[self loadAsynchronously];
}
-(void)loadDidFinish
{
[progressTimer stopActionByTag:kProgressLoop];
}