I am trying to scroll game background vertically and it works for some time and later background become empty. this is what I have tried:
var background = SKSpriteNode(imageNamed: "bgPlayScene")
func addBG() {
let backgroundTexture = SKTexture(imageNamed: "bgPlayScene")
let shiftBackground = SKAction.moveToY(-backgroundTexture.size().height, duration: 9)
let replaceBackground = SKAction.moveToY(backgroundTexture.size().height, duration: 0)
let movingAndReplacingBackground = SKAction.repeatActionForever(SKAction.sequence([shiftBackground,replaceBackground]))
for var i = 0; i<3; i++ {
println(i)
//defining background; giving it height and moving width
background=SKSpriteNode(texture:backgroundTexture)
background.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
background.size.width = self.frame.width
background.runAction(movingAndReplacingBackground)
self.addChild(background)
}
}
This is what I am getting: http://gyazo.com/3da3a267aeb030225fdb8c0d563276aa I don't know what I am missing.Please let me know if there is another better way to do this.