user3960314
user3960314

Reputation:

SpriteKit - Increase spawn time of Sprite

So I have this block of code. I want to increase the spawn time of the bubbles if the counter is 5. I have done some part of the code, but it is not working.

//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

    }

}

Upvotes: 0

Views: 71

Answers (1)

Darvas
Darvas

Reputation: 974

This should work, and this is less complicated. Run this function then you whant to start spawning your bubbles and cones

 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)
        ]))
}

Upvotes: 1

Related Questions