1

I'm trying to draw lines in Cocos2d using touches.

I had a system where it would just add a small sprite where you touched, but it's working terribly. So I've been trying to find a way to draw actual lines using a method like ccDrawLine, but every tutorial I find seems to leave out something, and I just can't figure it out.

I've found this tutorial, Drawing line on touches moved in COCOS2D but I don't understand a few things about that.

It seems to reference the same variable from two different files, so I don't understand how it's doing that. (The naughtyTouchArray variable)

I can't find a complete guide on drawing lines, so sorry for the codeless question, but I'm getting frustrated.

Thanks.

Community
  • 1
  • 1
Austin
  • 4,801
  • 6
  • 34
  • 54

1 Answers1

1

The answer you've linked in your question provides good solution to your problem. There is no "two different files". Just two different methods of one layer. One method (ccTouchesMoved:withEvent:) handles touches and fill the array of points to be connected to each other one-by-one with lines. From cocos2d documentation, all drawing must be placed in the draw method of the node. So, another (draw) method just draws lines according to the given array. Cocos2d is based on OpenGL and it fully redraws scene every tick, so you cannot just draw new line. You had to draw all of them.

Or any other node can draw your array in it's draw method, so you can simply pass stored array of points from the layer, that detects touches, to this node.

Morion
  • 10,495
  • 1
  • 24
  • 33