I am trying to display some alerts on screen after random amount of time. Following is the obj-C code for this. I am unable to convert it into C++. If anyone has used this technique, please help.
float delay = (float)(rand()%100)/100.0f*7. 0f+3.0f;
CCTimer *timer = [NSTimer scheduledTimerWithTimeInterval :delay target:self selector:@selector( displayRockAlert) userInfo:nil repeats:NO];
SOLUTION:
There is a CCScheduler class that is used in cocos2d to schedule CCTimers. If your class is a subclass of CCNode you can use the CCNode schedule() and unschedule() these timers. Assuming your class's name is GameLayer you'd write
schedule(schedule_selector( GameLayer::displayRockAlert), delay);to have your GameLayer displayRockAlert method called repeatedly after delay seconds.
Note that you'll need to unschedule it too with
unschedule(schedule_selector( GameLayer::displayRockAlert)); once you are in your displayRockAlert method
Also note that your displayRockAlert method should receive a single parameter of type ccTime if you're using this approach
schedule(schedule_selector(
Note that you'll need to unschedule it too with
unschedule(schedule_selector(
Also note that your displayRockAlert method should receive a single parameter of type ccTime if you're using this approach
0 comments:
Post a Comment