我目前正在製作一個sprite套件中的遊戲,並且我有8種方法,我寫了所有的時間碼ETC,因此每1秒調用一次方法,但是我希望它隨機調用一個方法八大方法,我一直在努力得到這個工作好幾個星期,任何幫助將長久地感謝,這是我的時刻碼 -Sprite Kit調用隨機方法
- (void)updateWithTimeSinceLastUpdate:(CFTimeInterval)timeSinceLast {
self.lastSpawnTimeInterval += timeSinceLast;
if (self.lastSpawnTimeInterval > 5) {
self.lastSpawnTimeInterval = 0;
[self shoot1];
}
}
- (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];
}
正如你所看到的,而不是[self shoot1]
我希望它隨機撥打一個八種方法中,所有的方法都被命名爲Shoot1,Shoot2,一直到Shoot8。三江源
[Sprite工具包,我怎麼可以隨機調用一個方法?](http://stackoverflow.com/questions/20716328/sprite-kit-how-can-i-randomly-call-a-method) – 2014-04-17 12:21:51
是的,我無法刪除,因爲它有答案 – user3110546