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).

4

0 回答 0