How do I have "drag and drop" active after "set position?"

Get help using Construct 2

Post » Sun Nov 20, 2016 2:57 am

Hello,

I am trying to use a touch screen to drag and drop icons around. In the attached capx, if you touch (or mouse click) on a blue icon, drag and drop works as expected. But I'd like to have an adjustable margin around the icons as well, so that if you touch the screen and you're a little off of an icon, but it's nearby, that icon is still dragged.

By doing a distance check between the icons and the touch location, I can select an icon and move it to the touch location, but then drag and drop (which is enabled) is "inactive" unless the user lifts up their finger and taps again. I could just make a larger collision polygon, but that has many downsides.

https://dl.dropboxusercontent.com/u/185 ... ouch1.capx

Other functionality in this capx is:

Touch large purple button on start for fullscreen. Triple touch or ESC to exit fullscreen (purple button reappears).

On touch start makes a red icon top left visible, on touch end toggles it back to invisible.

The best workaround I can think of is to have a variable toggle that bypasses "drag and drop" to set the icon's position to the touch position every tick until it's released. I suppose that's all the Drag and Drop behavior is doing anyway, so maybe that's not a big deal?

Thanks!

EDIT: I have two icons, and if I delete the Drag and Drop behavior from one, then the other works as expected?!
B
26
S
11
G
4
Posts: 30
Reputation: 3,937

Post » Sun Nov 20, 2016 11:05 am

I don't think you need anything that complicated. You can create an invisible sprite that is larger than the visible sprite and pinned to the visible sprite, which allows dragging when you are not quite touching it. You could also put them into a container so they are one object with part of it invisible. Really you are dragging the invisible sprite. Then you can say when the invisible sprite is 'in dragging', set the visible sprite to mouse.x,mouse.y so it is central.
B
47
S
18
G
84
Posts: 2,273
Reputation: 49,800

Post » Sun Nov 20, 2016 1:36 pm

Thanks for your advice, Plinkie!

My initial feeling is that your workaround isn't much better than mine once there are multiple invisible sprites overlapping each other, and I end up having to run distance checks anyway, disable drag and drop on the undesired sprite(s), unpin the desired icon, move it, repin it, re-enable drag and drop on the sprite(s) I left behind and so forth. Plus, I prefer working with numbers rather than images, since I find they're more adaptable to development changes down the road.

I've also had trouble getting things to look right (without a rubber band effect, as I recall) when mixing pin and drag and drop behaviors in the past.

But it's also very late where I am, so maybe I'm just being grumpy, and I'll give it some more thought after I've slept. ;) I definitely appreciate your time.

Either way, this would be a lot easier if Construct 2 had a "force drag" action, or if the current behavior realized that since there's a sprite under my finger, I want to drag it!
B
26
S
11
G
4
Posts: 30
Reputation: 3,937

Post » Sun Nov 20, 2016 1:48 pm

Because you're already touching and move the object to touch position I don't know how you can get this to work using that method but good luck. There is always a problem with overlapping objects and drag/drop but you can use a pick to pick one of them to drag if they are overlapping.
B
47
S
18
G
84
Posts: 2,273
Reputation: 49,800


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, dop2000, Lancifer and 28 guests