开发者

remove first image with interval

I am using...

[self addChild:self.blue_action];
[self schedule:@selector(updateTimer1:) interval:1.0f];

Via this line, I want to show an image in the any position and after some time that image will remove, through '[self removeChild: self.blue_action cleanUp:Yes];'

-(void)updateTimer1:(id)sender {
    if(time_1 == 0) {
        NSLog(@"time value ");
        [self removeChild:sel开发者_JAVA技巧f.blue_action cleanup:YES];
        [self schedule: @selector(updateTimer1:) interval:0.10];
    }
    else {
        --time_1;
    }
}


In this case the updateTimer1:(id)sender method was already scheduled. To schedule this again you obvious must unscheduled this method by [self unschedule:_cmd];

And it's a good practice do not remove sprite every time when you want it to disappear, try to just make it invisible self.blue_action.visible = NO


You want to fire method once after specific time? Action is helpful.

-(void)addBlueAction {
    [self addChild:self.blue_action];
    [self runAction:[CCSequence actions:
        [CCDelayTime actionWithDuration:1],
        [CCCallFunc actionWithTarget:self
            selector:@selector(removeBlueAction)],
        nil]];
}

-(void)removeBlueAction {
    [self removeChild:self.blue_action cleanup:YES];
}

If your app's target is for after iOS 4.0, you can use Blocks.

-(void)addBlueAction {
    [self addChild:self.blue_action];
    [self runAction:[CCSequence actions:
        [CCDelayTime actionWithDuration:1],
        [CCCallBlock actionWithBlock:^{

            [self removeChild:self.blue_action cleanup:YES];

        }],
        nil]];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜