As I mentioned in the commentary, you can create a beautiful parallax background using particles.
Add this function anywhere in your class.
//Creates a new star field func starfieldEmitterNode(speed speed: CGFloat, lifetime: CGFloat, scale: CGFloat, birthRate: CGFloat, color: SKColor) -> SKEmitterNode { let star = SKLabelNode(fontNamed: "Helvetica") star.fontSize = 80.0 star.text = "โฆ" let textureView = SKView() let texture = textureView.textureFromNode(star) texture!.filteringMode = .Nearest let emitterNode = SKEmitterNode() emitterNode.particleTexture = texture emitterNode.particleBirthRate = birthRate emitterNode.particleColor = color emitterNode.particleLifetime = lifetime emitterNode.particleSpeed = speed emitterNode.particleScale = scale emitterNode.particleColorBlendFactor = 1 emitterNode.position = CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMaxY(frame)) emitterNode.particlePositionRange = CGVector(dx: CGRectGetMaxX(frame), dy: 0) emitterNode.particleSpeedRange = 16.0 //Rotates the stars emitterNode.particleAction = SKAction.repeatActionForever(SKAction.sequence([ SKAction.rotateByAngle(CGFloat(-M_PI_4), duration: 1), SKAction.rotateByAngle(CGFloat(M_PI_4), duration: 1)])) //Causes the stars to twinkle let twinkles = 20 let colorSequence = SKKeyframeSequence(capacity: twinkles*2) let twinkleTime = 1.0 / CGFloat(twinkles) for i in 0..<twinkles { colorSequence.addKeyframeValue(SKColor.whiteColor(),time: CGFloat(i) * 2 * twinkleTime / 2) colorSequence.addKeyframeValue(SKColor.yellowColor(), time: (CGFloat(i) * 2 + 1) * twinkleTime / 2) } emitterNode.particleColorSequence = colorSequence emitterNode.advanceSimulationTime(NSTimeInterval(lifetime)) return emitterNode }
Then add this feature. This is a function that will create layers of stars. Just call this function, for example, in the didMoveToView file.
func createStarLayers() {
And this is how it looks.

source share