Apple Game Frameworks and Technologies: SKEffectNode not centered (p 149, B3)

On page 149 (of Beta 3) is this code to add a glow effect to the gloop droplets:

// Add glow effect
let effectNode = SKEffectNode()
effectNode.shouldRasterize = true
addChild(effectNode) 
effectNode.addChild(SKSpriteNode(texture: texture)) 
effectNode.filter = CIFilter(name: "CIGaussianBlur", parameters: ["inputRadius":40.0])

When run this shows a circular glow effect centered at the very top of the droplet where the drop number label is. The glow proceeds down about half of the drop and doesn’t provide any glow around the fattest part of the droplet. Much of glow is radiating out around the number label.

It does not look like the photo on page 149 which shows the glow surrounding the whole drop.

The cause is that the drop is a collectible which has the anchor point set to the middle top. The effect node was not given a position and is therefore centered on the anchor point by default.

To fix it in my code I added:

        effectNode.position = CGPoint(x: 0, y: -(frame.height / 2.0))

to position to effectNode halfway down the droplet in the true center.

I tried running the sample project in the end folder and it has the same bug with the glow not being centered the same way as the photo in the book.

1 Like