I'm using SpriteKit SKShapeNode to draw lines. I start drawing in touchesBegan, update the path in touchesMoved and add the completed line to an array in touchesCompleted. Now, I want to be able to erase segment from my lines, If the segment is not at the end or the beginning of the line, the line should be splitted into two different lines. Here is my code :
for segment in segments {
if segment.contains(touch){
segment.removeFromParent()
let index = segments.index(of: segment)
segments.remove(at: index!)
break
}
}
Segments contains all the line points. However, this function removes the whole line and not the touched segment of the line. Can you please help me so that I get the desired behaviour?
Thank you.