I've written a custom subclass of SKLabelNode which should apply a rudimental "drop shadow" to my label:
class ShadowLabel: SKLabelNode {
var shadowNode: SKLabelNode
init(fontNamed font: String = "Foo", text: String, size: CGFloat, zPosition zPos: CGFloat, shadowColor: SKColor = SKColor.black, shadowOffset: CGPoint = CGPoint(x: 0, y: -4), shadowAlpha: CGFloat = 0.5) {
shadowNode = SKLabelNode(fontNamed: font)
super.init(fontNamed: font)
self.text = text
self.fontSize = size
self.zPosition = zPos
shadowNode.text = self.text
shadowNode.zPosition = self.zPosition - 1
shadowNode.fontColor = shadowColor
shadowNode.position = shadowOffset
shadowNode.fontSize = self.fontSize
shadowNode.alpha = 0.5
self.addChild(shadowNode)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setNewText(_ newText: String) {
self.text = newText
self.shadowNode.text = newText
}
}
My problem is, that at runtime, the console gives me the following error:
use of unimplemented initializer 'init()' for class 'MyProject.ShadowLabel'
I use the custom subclass in my GameScene class as following:
class GameScene: SKScene {
var scoreLabel = (ShadowLabel(fontNamed: "Foo", text: "", size: 100, zPosition: 150, shadowColor: SKColor.black, shadowOffset: CGPoint(x: 0, y: -4), shadowAlpha: 0.5))
override func didMove(to view: SKView) {
scoreLabel.text = "\(gameScore.totalScore)" // a struct which counts the game score
scoreLabel.color = SKColor.white
scoreLabel.fontSize = 100
scoreLabel.zPosition = 150
scoreLabel.position = CGPoint(x: Scene.width/2, y: Scene.heigth - 40 - scoreLabel.frame.height)
addChild(scoreLabel)
}
}
I don't know why the parameter-empty init() call is made in the first place.
Any suggestion?