This is a SUPER easy way to start parallax background. WITH SCACKS! I hope this helps you understand the basics before moving on to a more complex but more efficient way of coding this. So I'll start with code that moves the background, and then try to duplicate the code for the foreground or the objects you want to fit into your scene.
var groundImage = SKTexture(imageNamed: "background.jpg")
var moveBackground = SKAction.moveByX(-groundImage.size().width, y: 0, duration: NSTimeInterval(0.01 * groundImage.size().width))
var resetBackGround = SKAction.moveByX(groundImage.size().width, y: 0, duration: 0.0)
var moveBackgoundForever = SKAction.repeatActionForever(SKAction.sequence([moveBackground, resetBackGround]))
for var i:CGFloat = 0; i<2 + self.frame.size.width / (groundImage.size().width); ++i {
var sprite = SKSpriteNode(texture: groundImage)
sprite.position = CGPointMake(i * sprite.size.width, sprite.size.height / 2)
sprite.runAction(moveBackgoundForever)
self.addChild(sprite)
}
}
/* , . , , . . , , , , , . , . , : ObjectiveC, Swift. !