I'm making a SpriteKit project where one game screen needs to allow the user to draw on the screen. I want to have a "delete all" button and an "undo" button. However, I can't find out how to delete a path anywhere online. Here's how I'm drawing my lines:
var pathToDraw:CGMutablePathRef!
var lineNode:SKShapeNode!
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
pathToDraw = CGPathCreateMutable()
CGPathMoveToPoint(pathToDraw, nil, touchLocation.x, touchLocation.y)
lineNode = SKShapeNode()
lineNode.path = pathToDraw
lineNode.strokeColor = drawColor
self.addChild(lineNode)
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
CGPathAddLineToPoint(pathToDraw, nil, touchLocation.x, touchLocation.y)
lineNode.path = pathToDraw
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {}
But now the problem is how can I delete them? I have tried lineNode.removeFromParent()
but it doesn't work. Any ideas?