2

I initially draw a line with an SKShapeNode.

    var path = CGPathCreateMutable()
    p0 = CGPointMake(-(self.frame.size.width/2), 100.0)
    CGPathMoveToPoint(path, nil, p0.x, p0.y)
    p1 = CGPointMake(self.frame.size.width/2, 100.0)
    CGPathAddLineToPoint(path, nil, p1.x, p1.y)
    line = SKShapeNode(path: path)
    line.strokeColor = UIColor.purpleColor()
    addChild(line)

This works fine. It draws a purple line across the screen. I am trying to update the path of that line in an update function that get's called 60 times a second. This curves the line based on the users finger.

override func update(currentTime: CFTimeInterval) {
    var path = CGPathCreateMutable()
    CGPathMoveToPoint(path, nil, p0.x, p0.y)
    CGPathAddQuadCurveToPoint(path, nil, fingerLocation.x, fingerLocation.y, p1.x, p1.y)
    line.path = path
}

As soon as the update function runs the line disappears. I don't know if I am using the right procedure of updating the path of the SKShapeNode. I can't seem to find any information about how to do so. I get the fingerLocation from the touchesMoved method using touch.locationInNode(self).

Cœur
  • 37,241
  • 25
  • 195
  • 267
Johnston
  • 20,196
  • 18
  • 72
  • 121
  • You're using `update:`, which will be called before each frame update. Keep in mind it won't always be called 60 times a second. – Andrew Aug 14 '14 at 14:08
  • @SantaClaus Good to know. Shouldn't it still work? It would be updated at that point correct? – Johnston Aug 14 '14 at 14:20
  • Possibly related to this http://stackoverflow.com/questions/21294642/sprite-kit-skshapenode-path-not-drawing-quad-curve – 0x141E Aug 14 '14 at 17:45

0 Answers0