Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
1  
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
1  
@Kaizer Sounds like the right way. Why don't you try it? –  Marton Jun 17 '13 at 9:00
    
you can see this :stackoverflow.com/questions/8749853/… –  shaqir saiyed Jul 23 '13 at 13:47
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.