首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

cocos2d中的schedule施用-转

2014-04-26 
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];

}

热点排行