3
votes

Calling this code inside the didMoveToView() of my SKScene:

let frame = CGRect(x: 30, y: 200, width: 100, height: 100)
let path = UIBezierPath(rect: frame)
UIColor.blackColor().setStroke()
path.stroke()
self.addChild(SKShapeNode(path: path.CGPath))

does absolutely nothing. The scene is empty (it has the default SKScene grey background). Here I'm just trying to draw a black unfilled rectangle (this is a simplified version of using SKShapeNode to draw a path, the original has more complicated drawing code).

2

2 Answers

3
votes

Your shape isn't showing because you haven't given the SKShapeNode a fill or stroke colour. Your code should instead be:

let path = UIBezierPath(rect: CGRect(x: 30, y: 200, width: 100, height: 100))

let shapeNode = SKShapeNode(path: path.CGPath)
shapeNode.strokeColor = UIColor.blackColor()
addChild(shapeNode)
2
votes

There is also a bug in the simulator that prevents SKShapeNodes from drawing paths. I found that the same code will work properly on hardware. I don't have a solution to have it show in the simulator.