Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working with cocos2d for the iPhone and I have a question about how to implement the following. I have a circle shaped sprite on my layer. When I touch the sprite and move my finger a line must be drawn from the sprite to where my finger is. When I move my finger on the screen the line must follow (straight line). When I release my finger the line should disappear. In a good looking way I should be able to restyle the line into an arrow.

Can anyone move me in the right direction for this ?

Kind regards

share|improve this question
And what have you done already? – Little Helper Jun 17 '13 at 7:01
hello,well beside adding the 2 sprites on the layer not much. I have read about the CCDrawLine method but I can't connect to how I can use it with the thing I need. A wild guess would be to keep track on the startpoint and updating the endpoint and draw method as long as you keep the touch but I don't know if that's the right way. – Kaizer Jun 17 '13 at 7:08
@Kaizer Sounds like the right way. Why don't you try it? – Marton Jun 17 '13 at 9:00
you can see this… – shaqir saiyed Jul 23 '13 at 13:47

I do something like this. Just store the start touch location on ccTouchesBegan, store you end point on ccTouchesMoved and then draw lines in the draw method between the 2 stored points.

share|improve this answer

You could use CCMotionStreak to achieve a nice fade effect for your line. This is how CCMotionStreak looks like.

If you want a simple line, without any fancy effects, then you can use the method [drawSegmentFrom] of CCDrawNode.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.