Simple SKTexture extension for creating gradient effect in SpriteKit.
CocoaPods:
Swift 2.2: pod 'SKTextureGradient', '~> 0.1' Swift 2.3: pod 'SKTextureGradient', '~> 2.3' Swift 3.0: pod 'SKTextureGradient', '~> 3.0'
Manual:
Copy SKTextureGradient.swift to your project.
let topColor = CIColor(rgba: "#71B280") let bottomColor = CIColor(rgba: "#134E5E") let texture = SKTexture(size: CGSizeMake(200, 200), color1: topColor, color2: bottomColor, direction: GradientDirection.Up) texture.filteringMode = .Nearest let sprite = SKSpriteNode(texture: texture) sprite.position = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame)) sprite.size = self.frame.size addChild(sprite)
SKTextureGradient is available under the MIT license. See the LICENSE file for more info.