I’m trying to play animations in sequence but I’m having issues playing them as a for loop iterates through the list of objects in an array.
it will move through the array but it won’t play each one it just plays the last.
-(void) startGame {
gramma.animationDuration = 0.5;
// Repeat forever
gramma.animationRepeatCount = 1;
int r = arc4random() % 4;
[colorChoices addObject:[NSNumber numberWithInt:r]];
int anInt = [[colorChoices objectAtIndex:0] integerValue];
NSLog(@"%d", anInt);
for (int i = 0; i < colorChoices.count; i++) {
[self StrikeFrog:[[colorChoices objectAtIndex:i] integerValue]];
//NSLog(@"%d", [[colorChoices objectAtIndex:i] integerValue]);
sleep(1);
}
}
it moves through the whole cycle really fast and sleep isn’t doing anything to allow it to play each animation… any suggestions?
Use an NSTimer so the run loop has time to process. Drawing does not begin until after startGame returns.
Edit:
To start it:
If you need to be able to stop the timer midway through, retain a reference to it so you can invalidate it as needed.