-1
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ And what have you done already? \$\endgroup\$ – Little Helper Jun 17 '13 at 7:01
  • \$\begingroup\$ 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. \$\endgroup\$ – Kaizer Jun 17 '13 at 7:08
  • 1
    \$\begingroup\$ @Kaizer Sounds like the right way. Why don't you try it? \$\endgroup\$ – Marton Jun 17 '13 at 9:00
  • \$\begingroup\$ you can see this :stackoverflow.com/questions/8749853/… \$\endgroup\$ – shaqir saiyed Jul 23 '13 at 13:47
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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