-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super initWithColor:ccc4(255,255,255,255)] )) {
[UIApplication sharedApplication].idleTimerDisabled = YES;
imageArray = [[NSMutableArray alloc]init];
winSize = [[CCDirector sharedDirector]winSize];
[self addEverything];
[self schedule:@selector(imageBlink) interval:5.0f];
}
return self;
}
-(void)imageBlink{
int tagNum = (arc4random() %9 )+1 ;
for (CCSprite *object in imageArray) {
if (object.tag == tagNum) {
[object runAction: [CCSequence actions:[CCBlink actionWithDuration:2 blinks:1],[CCFadeOut actionWithDuration:2], nil]];
[[SimpleAudioEngine sharedEngine]playEffect:@"slap.mp3"];
NSLog(@"blink");
return;
}
}
}
-(void)addImage{
self.imageTag = 1;
for (int i = 0; i <3; i++) {
for (int j =0; j<3; j++) {
image = [CCSprite spriteWithSpriteFrameName:@"0002.png"];
NSLog(@"%d",imageTag);
[image setTag:self.imageTag];
self.imageTag ++ ;
image.position = ccp(STAGE_WIDTH/(3)*(j)+35+41, STAGE_HEIGHT/(3)*(i)+115+41);
[imageArray addObject:image];
[image setVisible:NO];
[self addChild:image z:2];
}
}
}
I scheduled a method named imaged blink to be call every 5 seconds. The method would make my sprite from an array to blink(appear and disappear). But after several calls(about 10 or more), the sprite stops blinking. However, the output through NSLog “blink” still appears in 5s intervals. I have this problem on both the iphone emulator and my ipod. Thanks for help.
If an object is already running the blink sequence, and you run another, this may interfere with what’s happening on screen. I suggest to add the stopAllActions before running a new sequence.
The other thing I noticed is that you run a CCFadeOut action. Keep in mind that after this action is done, the sprite’s opacity will be 0 and CCBlink changes the visible property but does not affect opacity. That means you should ensure that the sprite is at maximum opacity before starting the sequence: