我正在编写我的游戏此刻在sprite工具包中,我有8种不同的方法,并且我设置了每5秒调用1个方法,但不是只能调用1个方法,我希望它随机选择8种方法中的1种,并称之为。这是我目前的代码:雪碧套件,我如何随机调用一个方法?
- (void)updateWithTimeSinceLastUpdate:(CFTimeInterval)timeSinceLast {
self.lastSpawnTimeInterval += timeSinceLast;
if (self.lastSpawnTimeInterval > 5) {
self.lastSpawnTimeInterval = 0;
[self shootPizza];
}
}
- (void)update:(NSTimeInterval)currentTime {
// Handle time delta.
// If we drop below 60fps, we still want everything to move the same distance.
CFTimeInterval timeSinceLast = currentTime - self.lastUpdateTimeInterval;
self.lastUpdateTimeInterval = currentTime;
if (timeSinceLast > 1) { // more than a second since last update
timeSinceLast = 1.0/60.0;
self.lastUpdateTimeInterval = currentTime;
}
[self updateWithTimeSinceLastUpdate:timeSinceLast];
}
找到为什么不叫一个方法并传入当前的随机数,然后使用switch(number){}为每个数字运行代码? – LearnCocos2D