我试图找出如何做一个事件每一个随机数。我使用下面的代码来获得50 + 100之间的随机数
int x = (arc4random() % 50) + 50;
然后我想根据返回值调用选择器。
[_hero schedule:@selector(randomAnimation) interval:x];
我试着在脑子里想,在New Random time
随机时间结束后,我该如何重新运行计划。
在_hero类中的randomAnimation方法:
-(void) randomAnimation {
// do the animation stuff here
// then
int x = (arc4random() % 50) + 50;
[self scheduleOnce:@selector(randomAnimation) delay:x];
}
并以
启动序列[_hero randomAnimation];
编辑:如果你不想暴露随机动画方法,当对象被添加到场景中时,像这样触发动画:
-(void) onEnter {
[super onEnter];
[self randomAnimation];
}