- init() can only call super.init()
- convenience init() can only call self.init()
Your super-class:
import SpriteKit
class BrickGO: SKSpriteNode {
// create a designated initializer
init() {
super.init(texture: nil,
color: .clear,
size: Nodes.Bricks.size)
self.anchorPoint = .zero
self.position = .zero
self.zPosition = .zero
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Your sub-class:
import SpriteKit
class BlueBrickGO: BrickGO {
override init() {
super.init()
self.name = "blue"
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Your super class:
import SpriteKit
class DefaultTEX: SKTexture {
// create your custom designated convenience init
convenience init(assetName: String) {
self.init(imageNamed: assetName)
self.filteringMode = .nearest
}
// a super.init() is needed because you want to use self.init(imageNamed: assetName)
// and you can't write super call in convenience init()
override init() {
super.init()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Your sub-class:
import SpriteKit
class GreenBrickTEX: DefaultTEX {
convenience override init() {
self.init(assetName: "green_brick")
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
also make sure you're calling your superclass not frameworks' .
if init color is purple you're not calling your superclass, you're calling apple's superclass .
Make sure it's green!
Also don't use similar naming.
Create more different name than "imageNamed:", "imageName:".
Create something like "init(texture anImageName: SKTexture)"