I'm playing with some Cocos2D code where I want to perform certain actions in sequence. For example, I have an icon created using a Sprite. I want that icon to FadeIn over a period of a second, after which I want that Sprite to participate in touch events, so that I know when the user touches it. The code would look something like this:
-(void) someMethod {
Sprite* myIcon = ... ;
[myIcon runAction:[Sequence actions:[FadeIn actionWithDuration:1], [CallFunc actionWithTarget:self selector:@selector(onFaded)], nil];
}
-(void) onFaded {
myIconParticipatesInTouch = true;
}
I'm not 100% sure, but I believe that I'm noticing that when I debug this code and do a break point somewhere in the middle of the fade action, the 1sec timer expires and sometimes my onFaded method never gets called. I haven't experienced this behavior when actually running the app full time. So, my question is this:
In the example above, is the callback function specified by CallFunc guaranteed to be called?
OR is there no such guarantee and I should use the following schedule pattern instead?
-(void) someMethod {
Sprite* myIcon = ... ;
ccTime fadeInterval = 1;
[myIcon runAction:[FadeIn actionWithDuration:fadeInterval]];
[self schedule:@selector(onFaded:) interval:fadeInterval];
}
-(void) onFaded:(ccTime)unused {
[self unschedule:@selector(onFaded:);
myIconParticipatesInTouch = true;
}