Reputation: 149
I have a method to add an enemy, and I want to know how I can make it so I run it a certain number of times (say 10). I call the method with a scheduler in cocos2d and by doing [self addEnemy]; Need any more info?
Upvotes: 0
Views: 302
Reputation: 69037
If the selector you schedule is methodA
:
[self schedule:@selector(methodA:) interval:1/60];
then a simple way to do what you are looking for is:
- (void) methodA:(ccTime)adelta {
static int counter = 10;
if (--counter >= 0) {
//-- do your processing
} else {
counter = 10; //-- this in case you want to reschedule the method at some later point
[self unschedule:@selector(methodA:)];
}
}
If you prefer it, you could use an ivar in your class to track the number of repetitions.
Upvotes: 1