我正在做一个英雄应该使用Sprite Kit和Swift跳过敌人的游戏。我有4种类型,但它们基本相同。当我对敌人的出现进行编码时,我认为如果它们可以出现在群组中就可以了,但现在我发现它并不是很好。如何在敌人之间制作一个随机范围?它应该为英雄提供足够的空间来至少从跳跃中降落。我尝试过,但结果却有些奇怪。 这就是我如何产生它们的原因:
func random() -> UInt32 {
var time = UInt32(60)..<UInt32(200)
return time.startIndex + arc4random_uniform(time.endIndex - time.startIndex + 1)
}
然后我有不同的外观文件:
class EnemyAppear {
var nowAppear = false
var waitToAppear = UInt32(0)
var appearInterval = UInt32(0)
init(nowAppear:Bool, waitToAppear:UInt32, appearInterval:UInt32) {
self.nowAppear = nowAppear
self.waitToAppear = waitToAppear
self.appearInterval = appearInterval
}
func shouldRun() -> Bool {
return self.appearInterval > self.waitToAppear
}
} 然后我有一个在屏幕上运行它们的功能
func enemyRun() {
for(enemy, enemyAppear) in self.enemyStatus {
var thisPet = self.childNodeWithName(enemy)!
if enemyAppear.shouldRun() {
enemyAppear.waitToAppear = random()
enemyAppear.appearInterval = 0
enemyAppear.nowAppear = true
}
然后对于每个敌人,我都有一个&#34;状态&#34;
var enemyStatus:Dictionary<String,EnemyAppear> = [:]
enemyStatus["mouse"] = EnemyAppear(nowAppear: false, waitToAppear: random(), appearInterval: UInt32(0))
我无法理解如何使它们看起来像那样,但彼此之间有空的空间以及放置它的位置。