Kim Kim - 1 year ago 76
iOS Question

changing to another background while playing game

func createBackgrounds() {
for i in 0...2 {
let bg = SKSpriteNode(imageNamed: "BG Day") = "BG"
bg.zPosition = 0;
bg.anchorPoint = CGPoint(x: 0.5, y: 0.5)
bg.position = CGPoint(x: CGFloat(i) * bg.size.width, y: 0)

If I want to add another background "BG Night" after 2 minutes while playing game, how can I write the codes?

Answer Source

Take a look at NSTimer:

var timer = NSTimer.scheduledTimerWithTimeInterval(120.0, target: self, selector: #selector(addBackground), userInfo: nil, repeats: false)

Then, create an addBackground function that creates another background image.

Hope this helps!