0

I'm having trouble finding a way to create a gradient background for an SKScene. I have tried using CAGradientLayer but to no success. The only way I know to change the background is to use, for example, backgroundColor = SKColor.cyan. But I want to just create a linear gradient to make the background of my scene look nice and smooth. As of now this is what I have tried and it does not work.

CODE:

    let gradientBG = CAGradientLayer()
    gradientBG.frame = (self.view?.bounds)!
    gradientBG.colors = [SKColor.black, SKColor.cyan]
    gradientBG.locations = [0.0, 0.5]
    gradientBG.startPoint = CGPoint(x: 0.0, y: 1.0)
    gradientBG.endPoint = CGPoint(x: 1.0, y: 0.0)
    gradientBG.zPosition = 1

    self.scene?.view?.layer.addSublayer(gradientBG)

is there any way to do this using CAGradientLayer? Am I missing anything? If you have any suggestions, I would love to hear. Thanks in advance!

demogorgon
  • 474
  • 4
  • 20

0 Answers0