Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active January 17, 2018 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/0c17b5fe731b35784edc139d05c7c5df to your computer and use it in GitHub Desktop.
Save laevandus/0c17b5fe731b35784edc139d05c7c5df to your computer and use it in GitHub Desktop.
SKSpriteNode with a glow
import SpriteKit
extension SKSpriteNode {
/// Initializes a textured sprite with a glow using an existing texture object.
convenience init(texture: SKTexture, glowRadius: CGFloat) {
self.init(texture: texture, color: .clear, size: texture.size())
let glow: SKEffectNode = {
let glow = SKEffectNode()
glow.addChild(SKSpriteNode(texture: texture))
glow.filter = CIFilter(name: "CIGaussianBlur", withInputParameters: ["inputRadius": glowRadius])
glow.shouldRasterize = true
return glow
}()
let glowRoot: SKNode = {
let node = SKNode()
node.name = "Glow"
node.zPosition = -1
return node
}()
glowRoot.addChild(glow)
addChild(glowRoot)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment