SpriteKit - 增加 Sprite 的生成时间

SpriteKit - Increase spawn time of Sprite

所以我有了这段代码。如果计数器为 5,我想增加气泡的生成时间。我已经完成了部分代码,但它不起作用。

//This spawn bubbles every "delayBubbleSpawn"
   var delayBubbleSpawn = SKAction.waitForDuration(3.0)


    //Running the bubble and cone action
    runAction(SKAction.sequence([SKAction.runBlock(addCones),
        SKAction.repeatActionForever(SKAction.sequence([SKAction.runBlock(addBubbles),
            delayBubbleSpawn]))]))



override func update(currentTime: CFTimeInterval) {
    scoreLabel?.text = "Score : \(score)"

    if counter_speed == 5 { //if score is 5, increase spawning time
        actionForKey("delayBubbleSpawn")!.speed += 20.0

    }

}

这应该可行,而且不那么复杂。 运行 这个函数然后你想开始生成你的气泡和锥体

 func spawnBubbles() {

    let bubbleDelayTime: NSTimeInterval = 3.0
    if counter_speed == 5 {

        bubbleDelayTime = 25.0
    }

    addCones()
    addBubbles()

    runAction(SKAction.sequence([
        SKAction.waitForDuration(bubbleDelayTime),
        SKAction.performSelector(spawnBubbles(), onTarget: self)
        ]))
}