How to display a timer in a Cocos2d game? -
i'm trying display timer in cocos2d game shows number of minutes:seconds:milliseconds user has spent on level. i've searched examples , found should not using nstimer. understand should using cctimer class, i'm having tough time finding decent examples.
//declare in interface cclabelttf *mtimelbl; float mtimeinsec;
//init in onenter
mtimeinsec = 0.0f; [self schedule:@selector(tick:)];
//function used
-(void)tick:(cctime)dt { if(self.isgamepaused || self.isgameover) return; mtimeinsec +=dt; float digit_min = mtimeinsec/60.0f; float digit_hour = (digit_min)/60.0f; float digit_sec = ((int)mtimeinsec%60); int min = (int)digit_min; int hours = (int)digit_hour; int sec = (int)digit_sec; [mtimelbl setstring:[nsstring stringwithformat:@"%.2d:%.2d:%.2d",hours, min,sec]]; }
Comments
Post a Comment