1

I want to create a Sprite that has an alpha value and sits on top of some other nodes.

let objects = SKSpriteNode(imageNamed: "objects")
let blurredOverlay = SKSpriteNode(imageNamed: "overlay")
addChild(objects)
addChild(blurredOverlay)

My intention is to add a visual effect to the 'blurredOverlay' Node so that only the nodes that are overlapped by this node show the blurred effect?

Anyone with an idea?

boehmatron
  • 713
  • 5
  • 15

1 Answers1

1

This answer take and modify code from: Add glowing effect to an SKSpriteNode

For you solution:

Swift 3

let objects = SKSpriteNode(imageNamed: "objects")
let blurredOverlay = SKSpriteNode(imageNamed: "overlay")

let effectNode = SKEffectNode()
    effectNode.shouldRasterize = true
    effectNode.zPosition = 1
    effectNode.alpha = 0.5
    effectNode.addChild(SKSpriteNode(texture: blurredOverlay.texture))
    effectNode.filter = CIFilter(name: "CIGaussianBlur", withInputParameters: ["inputRadius":30])
    objects.addChild(effectNode)


addChild(objects)

Example: (Up tree have a blurredOverlay)

enter image description here

On the example images "objects" and "overlay" are the same image.

Community
  • 1
  • 1
Maetschl
  • 1,330
  • 14
  • 23