Having problems subclassing an CGpath as an SKShape

I am trying to create four walls, that would surround the screen.

From GameScene I call
Code Block
let leftWall  = MyEdge(side: Walls.left)


The code below works. But then I cannot add it as a child to GameScene, also I would like to give it an SKPhysicsBody.

My problem is figuring out the super.init. I've tried

super.init(texture: nil, color: .clear, size: CGPath(w: 0, h: 0))
super.init()

But I always get

Type of expression is ambiguous without more context



Code Block
class MyEdge {
let yourline = SKShapeNode()
let pathToDraw = CGMutablePath()
var color : SKColor
var startAt : CGPoint
var endAt : CGPoint
var colMask : UInt32
var conMask : UInt32
var catMask : UInt32
var name : String
init(side: Walls){
let whichWall = side
switch whichWall
{
case .left:
myGlobalVars.backGround!.size.height+1)
startAt = CGPoint(x: 5, y: 5)
endAt = CGPoint(x: 5, y: myGlobalVars.safeSceneRect.size.height-5)
color = .white
colMask = bodyMasks.gemMask.rawValue
conMask = bodyMasks.blankMask.rawValue
catMask = bodyMasks.edgeMask.rawValue
name = "left"
}
pathToDraw.move(to: startAt)
pathToDraw.addLine(to: endAt)
yourline.lineWidth = 2
yourline.path = pathToDraw
yourline.strokeColor = color
}
}

Answered by SergioDCQ in 645217022
Please ignore this question. It shows why I should never be allowed to program. My code is riddled with errors everywhere; not initializing variables, misunderstanding the error msgs I was receiving, etc. etc. etc.

Above that I have to do all that BEFORE calling
Code Block
super.init(texture: nil, color: .clear, size: .zero)

Where did you find this initialiser for CGPath
Code Block
CGPath(w: 0, h: 0)

Did you try:
Code Block
CGPath(rect: .zero, transform: nil)

I've been throwing everything I can, hoping something will stick.

CGPath(rect: .zero, transform: nil)

Produces:

Incorrect argument label in call (have 'rect:transform:', expected 'rect:cornerRadius:')
Replace 'transform' with 'cornerRadius'

Which I do, finally resulting in:
Code Block
super.init(rect: .zero, cornerRadius: CGFloat(0.0))

And the error I get is:

Must call a designated initializer of the superclass 'SKShapeNode'


Could you show the full code of the where you call the initialiser ?
Accepted Answer
Please ignore this question. It shows why I should never be allowed to program. My code is riddled with errors everywhere; not initializing variables, misunderstanding the error msgs I was receiving, etc. etc. etc.

Above that I have to do all that BEFORE calling
Code Block
super.init(texture: nil, color: .clear, size: .zero)

Good you found.

But a few advices to better use the forum and help others to help you:
  • read the answers and answer to such questions as : "Where did you find this initialiser for CGPath"

  • post code, otherwise, we get no context. How to find which super.init you call, you don't show this statement in your code.

=> That's absolute need. It is not enough to post code that is not directly relevant.

BTW, you didn't yet tell on what super init is called…
Having problems subclassing an CGpath as an SKShape
 
 
Q