Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: JennaReanne on May 30, 2013, 05:14:16 PM

Title: [SOLVED] Differentiate between a click and a drag?
Post by: JennaReanne on May 30, 2013, 05:14:16 PM
Hello all,
I have an object in my game that needs to accept as input both clicking and dragging.  The player can click on the object to perform an action, or drag the object somewhere on the screen to perform a different action.

What is the best way to differentiate between clicking and dragging?  The MOUSE DRAG global transition seems to fire whenever you click the mouse button, regardless of whether you drag or not.

Thank you!
-Jenna
Title: Re: Differentiate between a click and a drag?
Post by: jeanfabre on May 31, 2013, 02:21:59 AM
Hi,

 yes, you should check for the drag delta or the drag position, if it goes beyond a treshold than the user is dragging.

so, always assume the user is not dragging, but under the hood, keep track of the total touch position drift, and trigger a drag then, say when the current touch is at least 5 pixels away from the touch began position.

does that make sense?

bye,

 Jean
Title: Re: Differentiate between a click and a drag?
Post by: JennaReanne on May 31, 2013, 03:47:34 PM
Hi Jean,
In theory, yes, that makes total sense.  I'm just not exactly sure how to implement it.  The "Get Mouse X" and "Get Mouse Y" actions don't have options for "Every Frame", and the only other way I could think to implement it created an infinite loop.

I also tried using this action http://hutonggames.com/playmakerforum/index.php?topic=1644.msg7201#msg7201 (http://hutonggames.com/playmakerforum/index.php?topic=1644.msg7201#msg7201) but it didn't seem to work properly.  Any additional suggestions would be much appreciated :)

Thanks!
-Jenna
Title: Re: Differentiate between a click and a drag?
Post by: jeanfabre on June 03, 2013, 02:38:05 AM
Hi,

 Ok, Please find a working example. Let me know if you have difficulties understanding, but the process is simple, you watch for the magnitude of the drag to know if the user is dragging or not,

bye,

 Jean
Title: Re: Differentiate between a click and a drag?
Post by: JennaReanne on June 04, 2013, 10:14:12 AM
Hi Jean - that worked brilliantly, thank you so much!  It also introduced me to a few new things - the "Get Mouse Position" action is super useful, and the Vector3 Operator set to "Distance" is new and useful to me as well.

Thank you again!