【发布时间】:2014-01-19 16:17:06
【问题描述】:
我目前正在使用 sprite kit 制作游戏,我有 8 个方法,我已经编写了所有计时代码 E.T.C,所以它每 1 秒调用一个方法,但我希望它随机调用八种方法中的一个,我数周以来一直试图让它工作,任何帮助将不胜感激,这是我的计时代码-
- (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。谢谢你
【问题讨论】:
-
是的,我无法删除,因为它有答案
标签: iphone objective-c random sprite-kit