cocos2d中的schedule施用-转

cocos2d中的schedule使用-转cocos2d中的schedule有两种作用1)定时执行方法,例如每隔3秒钟执行一次方法fire

cocos2d中的schedule使用-转
cocos2d中的schedule有两种作用

1)定时执行方法,例如每隔3秒钟执行一次方法fire

看例子:

- (id) init{

    if((self = [super init])){

    [game addChild:self]

    [self schedule:@selector(fire) interval:3];

    }

    return self;

}

- (void) fire{

NSLog(@"fire");

}

2)延时执行方法,例如5秒种后执行方法destory

看例子:

- (id) init{

    if((self = [super init])){

    [game addChild:self]

    [self schedule:@selector(destory) interval:5];

    }

    return self;

}

- (void) destory{

NSLog(@"destory");

[self unschedule:@selector(destory)];

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

}