我如何才能使炸弹掉落的速度更快,或者游戏持续的时间越长,其产生速度越快?我想让您的生存时间越长,让我的游戏就越难。我希望它每10枚炸弹变硬。我已经研究了好几天,并尝试过对类似问题的多个答案。我相信我制造炸弹的方式使我很难做到这一点。提前致谢!

var bombSpawnSpeed : NSTimeInterval = 0.40
var bombCounter : Int = 0

这是在我的更新函数中。我的理解是,这只是整个场景的定期更新功能。
  override func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */

  if bombCounter >= 10 {
        if bombSpawnSpeed > 0.15 {
            bombSpawnSpeed -= 0.05
            bombCounter = 0

        }
        else {
            bombSpawnSpeed = 0.1

        }

    }

这是炸弹
func enemies() {

    let bomb1 = SKSpriteNode(imageNamed: "AtomicBomb")
    let bomb2 = SKSpriteNode(imageNamed: "EMP")
    let bomb3 = SKSpriteNode(imageNamed: "BioBomb")
    let bomb4 = SKSpriteNode(imageNamed: "ChemBomb")

    let enemy = [bomb1, bomb2, bomb3, bomb4]


    // Enemy Physics
    for bomb in enemy {
        bomb1.size = CGSize(width: 55, height: 55)
        bomb2.size = CGSize(width: 55, height: 70)
        bomb3.size = CGSize(width: 30, height: 30)
        bomb4.size = CGSize(width: 45, height: 70)


        bomb.physicsBody = SKPhysicsBody(circleOfRadius: bomb.size.width / 4)
        bomb.physicsBody?.categoryBitMask = PhysicsCategory.enemy
        bomb.physicsBody?.collisionBitMask = PhysicsCategory.missile | PhysicsCategory.airDefense
        bomb.physicsBody?.contactTestBitMask = PhysicsCategory.missile | PhysicsCategory.airDefense
        bomb.physicsBody?.affectedByGravity = false
        bomb.runAction(SKAction.speedBy(10, duration: 30))
        bomb.physicsBody?.dynamic = true
        bomb1.name = "enemy1"
        bomb2.name = "enemy2"
        bomb3.name = "enemy3"
        bomb4.name = "enemy4"

        print("bomb")

    }

    let deployAtRandomPosition = arc4random() % 4

    switch deployAtRandomPosition {
    case 0:
        bomb1.position.y = frame.size.height

        let PositionX = arc4random_uniform(UInt32(frame.size.width))

        bomb1.position.x = CGFloat(PositionX)

        self.addChild(bomb1)

        break

    case 1:
        bomb2.position.y = frame.size.height

        let PositionX = arc4random_uniform(UInt32(frame.size.width))

        bomb2.position.x = CGFloat(PositionX)

        self.addChild(bomb2)

        break

    case 2:
        bomb3.position.y = frame.size.height

        let PositionX = arc4random_uniform(UInt32(frame.size.width))

        bomb3.position.x = CGFloat(PositionX)

        self.addChild(bomb3)

        break

    case 3:
        bomb4.position.y = frame.size.height

        let PositionX = arc4random_uniform(UInt32(frame.size.width))

        bomb4.position.x = CGFloat(PositionX)

        self.addChild(bomb4)

        break

    default:

        break

    }

   bomb1.runAction(SKAction.moveTo(airDefense.position, duration: 5))
   bomb2.runAction(SKAction.moveTo(airDefense.position, duration: 5))
   bomb3.runAction(SKAction.moveTo(airDefense.position, duration: 5))
   bomb4.runAction(SKAction.moveTo(airDefense.position, duration: 5))

}

这就是我所呼吁的,开始制造炸弹
enemyTimer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: Selector("enemies"), userInfo: nil, repeats: true)

最佳答案

我认为更好的方法是

  • 添加一个名为lastTimeAddedBomb的新变量
  • 通过跟踪释放
  • 的炸弹数量来确定间隔
  • 检查是否需要在update方法
  • 中添加新炸弹

    像这样:
    var lastTimeAddedBomb:NSDate
    var numberOfBombsDropped:Int = 0
    var difficultyLevel:Float = 1
    
    override func update(currentTime: CFTimeInterval) {
    
        if (numberOfBombsDropped % 10 == 0) {
            difficultyLevel-= 0.1;
        }
    
        let intervalForBombs = difficultyLevel
    
        let timeFromLastBomb = NSDate().timeIntervalSinceDate(lastTimeAddedBomb)
        if (timeFromLastBomb >= intervalForBombs) {
            //call bomb
            //save last bomb date as now
            numberOfBombsDropped++
            lastTimeAddedBomb = NSDate()
        }
    }
    

    关于ios - 我如何才能使炸弹掉落的速度更快,或者游戏持续的时间越长,其产生速度越快?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35263732/

    10-14 18:42