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

Hi, David.

The image on that page was done in post since it was very difficult to capture a screenshot of a falling drop with any level of success.

Regarding the effect node’s position: I prefer to have the glow closer to the top of the drop to help the number stand out, which is why I didn’t adjust its position; but, yes, moving the effect node’s position—as you did—will more closely match the image in the book.

I may end up recreating that image, if possible. And I’ve updated the text to read:

Build and run the project, and you’ll see a faint glow around the top of each drop.

You’ll see this update in the next release. Thanks for letting me know.

EDIT: Good news! I was able to adjust the image. Thank goodness for source files and layers! :smile:

1 Like