Am trying to subclass SKShapeNode yet it never works. Specifically the SKShapeNode(rectOf: CGSize).
Trying to use init(), super.init, and sometimes the compiler tells me to use the designated initializer, which I cannot find to save my life. Am using Xcode 11 and Swift 5.
Here is a sample of one of my declaration attempts and my call. The self element in the call is from the background pic. It works if I create an SKShapeNode directly using the same parameters. But would like to subclass this so I can add custom methods and properties.
I've scoured the internet and so many other forums. Not one reply. I'm desperate at this point.
Thank you
p.s. I apologize this is a repost. But I only realized too late that I used the wrong tags.
In this sample code I removed all the part that fill color, and position, set the zPosition, etc. because it all works if I do it straight from my GameScene, without using a custom SubClassed attempt.
Trying to use init(), super.init, and sometimes the compiler tells me to use the designated initializer, which I cannot find to save my life. Am using Xcode 11 and Swift 5.
Here is a sample of one of my declaration attempts and my call. The self element in the call is from the background pic. It works if I create an SKShapeNode directly using the same parameters. But would like to subclass this so I can add custom methods and properties.
I've scoured the internet and so many other forums. Not one reply. I'm desperate at this point.
Thank you
p.s. I apologize this is a repost. But I only realized too late that I used the wrong tags.
In this sample code I removed all the part that fill color, and position, set the zPosition, etc. because it all works if I do it straight from my GameScene, without using a custom SubClassed attempt.
Code Block class PegBase : SKShapeNode { init(rectOfPegBase: CGSize) { super.init() self.fillColor = SKColor.red self.strokeColor = SKColor.red self.Position = 0 } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }} let childP = PegBase(rectOfPegBase: CGSize(width: self.size.width * 0.8, height: self.size.height * 0.2)) self.addChild(childP)