-1
\$\begingroup\$

I have a ball sprite and I apply physics to it when the user swipes on it. I'd like the ball to start moving in the direction of the swipe.

How can I do this?

\$\endgroup\$
6
  • 2
    \$\begingroup\$ This question appears to be off-topic because it is about debugging your code for you. \$\endgroup\$ Commented Feb 18, 2014 at 9:43
  • \$\begingroup\$ when ever I swipe on the sprite it must go in that direction only,i have added physics to that sprite. \$\endgroup\$ Commented Feb 18, 2014 at 11:13
  • \$\begingroup\$ Instead of including your non-working code and asking "how do I fix this". Why don't you tell us what your algorithm is, or ask how to implement the specific part of the algorithm that's not working. It's not clear from your question what the problem with the code is, this makes it far more difficult to debug. \$\endgroup\$ Commented Feb 18, 2014 at 16:59
  • \$\begingroup\$ @Byte56 : ThankS bro ,I have edited my question. can you help me out with that ? \$\endgroup\$ Commented Feb 20, 2014 at 3:14
  • 1
    \$\begingroup\$ I made some more clarifications and voted to re-open. Some more conceptual details on what you've tried or where you're getting stuck would help. For instance: Have you got swipe detection working? Are you using your own physics or a library like Box2D for AndEngine? (It just helps "aim" an answer.) \$\endgroup\$ Commented Feb 20, 2014 at 7:12

1 Answer 1

1
\$\begingroup\$

I have never written code for andengine but some pseudo like this may work:
OnTouch: You want to get the touch position.
OnRelease: You want to get the release position.
Theese two points can be used to create a direction vector. (The angle in between the points).

If you want, you can also use the distance between the points as force, but most likely you would like to use know how fast the user moved his finger, and you could initialize a timer on touch and stop it on release to know how fast moved his finger, and then multiply the delta-time with some speed variable.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.