func createBackgrounds() {
for i in 0...2 {
let bg = SKSpriteNode(imageNamed: "BG Day")
bg.name = "BG"
bg.zPosition = 0;
bg.anchorPoint = CGPoint(x: 0.5, y: 0.5)
bg.position = CGPoint(x: CGFloat(i) * bg.size.width, y: 0)
self.addChild(bg)
}
}
如果我想添加另一个背景" BG Night"在玩游戏2分钟后,我该如何编写代码?
答案 0 :(得分:0)
看看NSTimer:
var timer = NSTimer.scheduledTimerWithTimeInterval(120.0, target: self, selector: #selector(addBackground), userInfo: nil, repeats: false)
然后,创建一个addBackground函数,创建另一个背景图像。
希望这有帮助!