Good day, In Spritekit my code fails because I am obliged by GKComponent to implement:
a. a "required init" I do not need. b. At run time it calls this instead of my normal init() and fails. c. super.init(coder: aDecoder) does not solve my problem of calling it
Question: A Solution to call my init instead of this forced required init
In other answers suggest a solution to use super.init(coder: aDecoder) but it has not solved my problem of not calling it.
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//This code is supposed to add a simple eplipse under the sprite to make //a shadow effect by making it a GKComponent and add it to a GKEntity.
import Foundation
import GameplayKit
import SpriteKit
//GKEntity to add GKComponents
class Entity: GKEntity{
//A variable that is a GKComponent defined as ShadowComponent: GKComponent
var shadow: ShadowComponent
//My init
override init() {
shadow = ShadowComponent(size: CGSize(width: 50, height: 50), offset: CGPoint(x: 0, y: -20))
super.init()
addComponent(shadow)
}
//Forced by compiler to have it
**required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}**
}