How do I detect drag direction?

0 favourites
  • 5 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • In my game, an object has the DragNDrop behaviour. To adapt how other sprites around behave, I need to know the direction the drag is going.

    How can I do that ?

    Tagged:

  • Create two instance variable for the object and set them while dragging: prevX and prevY. Set up an event to check before you update the variables.

    So something like:

    Object Is dragging

    1) if object.prevX < object.X then you know the object has moved to the right, etc.

    2) set object.prevX to object.X

    You have to do the comparison before you update the variables, otherwise prevX and X will be the same.

  • Hope this example give you an idea: dropbox.com/s/p2p9h1b2ite63bq/tomb_miner.capx

  • You can add Touch object to the project and use Touch.AngleAt(0) and Touch.SpeedAt(0) expressions. They should work when dragging with mouse too. For example, this is dragging to the right:

    Sprite is dragging
    Touch.AngleAt(0) is within 30 degrees of 0
    Touch.SpeedAt(0)>100 
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Create two instance variable for the object and set them while dragging: prevX and prevY. Set up an event to check before you update the variables.

    So something like:

    Object Is dragging

    1) if object.prevX < object.X then you know the object has moved to the right, etc.

    2) set object.prevX to object.X

    You have to do the comparison before you update the variables, otherwise prevX and X will be the same.

    Woaw, thank you :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)