-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\$
  • 2
    \$\begingroup\$ This question appears to be off-topic because it is about debugging your code for you. \$\endgroup\$ – MrCranky Feb 18 '14 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\$ – Uday Feb 18 '14 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\$ – MichaelHouse Feb 18 '14 at 16:59
  • \$\begingroup\$ @Byte56 : ThankS bro ,I have edited my question. can you help me out with that ? \$\endgroup\$ – Uday Feb 20 '14 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\$ – Anko Feb 20 '14 at 7:12
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.

| improve this answer | |
\$\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.