我正在編寫我的遊戲此刻在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