I’m attempting to add a shadow / glow effect to an SKLabelNode by using NSShadow, however I can’t get it to work, can someone tell me where I’m wrong in my code?
var musicMenuText : NSAttributedString {
let shadow = NSShadow()
shadow.shadowBlurRadius = 5
shadow.shadowColor = UIColor.white
// shadow.shadowOffset = CGSize(width: 12, height: 12)
let musicOn = UserDefaults.standard.bool(forKey: UDKeys.musicOn)
let str1 = “Music ”
let attrs1: [NSMutableAttributedString.Key: Any] = [
.font: menuFont, .foregroundColor: UIColor.white]
let attributedStr1 = NSMutableAttributedString(string: str1, attributes: attrs1)
let str2 = “\(musicOn ? “On” : “Off”)”
let attrs2: [NSAttributedString.Key: Any] = [
.font: menuFont,
.foregroundColor: musicOn ? UIColor.green : UIColor.red,
.shadow: shadow
]
let attributedStr2 = NSMutableAttributedString(string: str2, attributes: attrs2)
attributedStr1.append(attributedStr2)
return attributedStr1
}
// Then I’m assigning the above to:
let menu3a = SKLabelNode(text: “Music”)
menu3a.attributedText = musicMenuText
menu3a.name = “Music”
menu3a.position = CGPoint(x: frame.midX, y: frame.height * 0.30)
addChild(menu3a)