Make SpriteKit SKSpriteNode glow

3 10 2015

so you’re making your spritekit game, and you want the user to know they should click on a button, but you’re not sure what the best way to do this is. well you have come to the right place.  I’ve run into this issue and have tried a few methods and found a method that really looks cool and is easy to implement. the two basic steps are to copy the SKSpriteNode, place it directly on top of itself, and  change the blendMode to “add” this will make the entire node look like it is glowing. Now the secret sauce is to setup an SKAction loop to continually change the alpha of this new node from 0 to lets say 0.3. this will make a pulsing glow effect on your original skspritenode that looks really neat and is clear to the user that they should click it! here is the code, enjoy!

// this is our original node that we want to make glow
playButton.anchorPoint = CGPointMake(0.0, 0.0)

// create a copy of our original node create the glow effect
let glowNode : SKSpriteNode = playButton.copy() as! SKSpriteNode
glowNode.size = playButton.size
glowNode.position = CGPoint(x: 0, y: 0)
glowNode.anchorPoint = playButton.anchorPoint
glowNode.alpha = 0.5
glowNode.blendMode = SKBlendMode.Add

//create the skaction loop that fades in and out
let fadeOut = SKAction.fadeAlphaTo(0, duration: 1)
let fadeIn = SKAction.fadeAlphaTo(0.3, duration: 1)
let forever = SKAction.repeatActionForever(SKAction.sequence([fadeOut, fadeIn]))

// add the new node to the original node

// add the original node to the scene



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: