Am trying to subclass SKShapeNode yet it never appears. I followed it into the debugger and am going through the init method, with the parameters I send in. But obviously I'm doing something wrong.
Here is my declaration 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:
Thank you
Here is my declaration 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:
Thank you
Code Block class PegBase : SKShapeNode { init(rectOfPegBase: CGSize) { super.init() self.fillColor = SKColor.red self.strokeColor = SKColor.red self.zPosition = 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)
Finally found the answer to this, after a long time, and after a lot of searching. Originally wanted to do it with SKSpriteNode. And Apple's Dox did say there were plenty of init options. Well the one thing I never thought to try was passing a nil to one of the defined init parameters. And that was that.
Code Block class GuessSlot : SKSpriteNode{ init(color: SKColor, size: CGSize) { super.init(texture: nil, color: color, size: size) } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } }