Jump to content

How detect drag direction


jkl_69
 Share

Recommended Posts

  • 2 weeks later...

First thanks for your answer.

 

But in this examples the sprits is ALWAYS locked for one Direction.

My Intention is lock different axis each times when I start drag depends on the trend of movement.

 

If I start drag the sprite mainly horizontally I will lock the vertical Movement and opposite.

Link to comment
Share on other sites

You could do the following (just an idea).

 

Get the current pointer position.

Define a variable to save past position and a variable to save the current direction.

If the past variable is empty then ignore this step. If it has past results, compare them to the current pointer position. Which one changed the most, x or y?

Update the direction with the result from the previous step.

Update the past position with current position.

 

Put that on a function and call it on update()

 

Now you have a variable that contains the direction of the pointer position. Proceed to move the sprite on the desired axis.

 

This is the first thing that came to my head, I haven't tested it. Please give it a try and tell me if it helped :)

 

Good luck!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...