SKShapeNode Path not updating

873 Views Asked by At

I've created an circle with an UIBezierPath which I add to a SKShapeNode. The circle displays fine. But when I want to update the path nothing happens. I keep seeing the same initial path I created. Do I have to call some kind of update function for the path to update properly? Color changes and stroke changes work fine but the path remains unchanged.

 override init(texture: SKTexture?, color: UIColor, size: CGSize) {
    shape = SKShapeNode.init()

    endAngle = CGFloat(endAngle) * CGFloat(M_PI) / 180.0
    startAngle = CGFloat(startAngle) * CGFloat(M_PI) / 180.0

    let circlePath : UIBezierPath = UIBezierPath.init(arcCenter: CGPoint(x:0,y:0), radius: 30, startAngle: startAngle, endAngle: endAngle , clockwise: true)

    super.init(texture: texture, color: color, size: size)

    shape!.path = circlePath.cgPath
    shape!.fillColor = UIColor.red
    addChild(shape!)

}


func changePath () {
    self.endAngle -= 0.1
    self.circle.path = nil

    let circlePath : UIBezierPath = UIBezierPath.init(arcCenter: CGPoint(x:0,y:0), radius: 35, startAngle: startAngle, endAngle: self.endAngle , clockwise: true)
    self.circle.path = circlePath.cgPath
}
1

There are 1 best solutions below

0
On BEST ANSWER

It looks like the SKShapeNode you are referring to in your changePath function isn't the same an in the initializer above. Updating the path on the correct node should do the trick!