0

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.

freeNinja
  • 365
  • 1
  • 4
  • 11
  • 1
    Don't just show the `for()` loop. People will need to see much more to help you. Strip your code down to the smallest snippet that will compile and run, and post that snippet to your question. Then everyone here can help you more effectively. – SaganRitual Mar 12 '18 at 21:46
  • The segment contain all the line (`CGPath`) points. Probably, you should think to get all points from your line: try to take a look to [this answer](https://stackoverflow.com/a/36374209/1894067). When you have all your points, you can think to rebuild your `CGPath` / `CGPath`s as you prefeer by removing some parts of your path. – Alessandro Ornano Mar 13 '18 at 16:03

0 Answers0