每个随机数呼叫事件

时间:2014-06-09 10:58:43

标签: ios cocos2d-iphone int

我试图弄清楚每个随机数如何做一个事件。我使用以下内容获得50 + 100之间的随机数

int x = (arc4random() % 50) + 50;

然后我想根据返回的值调用选择器。

[_hero schedule:@selector(randomAnimation) interval:x];

我试图在我的头脑中解决如何在New Random time的随机时间结束后重新运行计划。

1 个答案:

答案 0 :(得分:1)

_hero类randomAnimation方法中的

-(void) randomAnimation {

    // do the animation stuff here

    // then

    int x = (arc4random() % 50) + 50;
    [self scheduleOnce:@selector(randomAnimation) delay:x];


}

并使用

启动序列
[_hero randomAnimation];

编辑:如果您不想公开randomAnimation方法,请在将对象添加到场景时触发动画,如下所示:

-(void) onEnter {
    [super onEnter];
    [self randomAnimation];
}