How do I make drag and drop possible for very small sprites?

Get help using Construct 2

Post » Thu Jan 05, 2017 3:08 am

Hello everyone,

I've been trying to run my C2 game on a smartphone and everything works great, except for one thing: The drag and drop sprites are too small for my big-ass thumb to drag them around.

Now I'm trying to find a way to make the drag possible though without adjusting the size of the collision polygon, because that would compromise the whole project. I've tried the following thing:

- I've created an invisible sprite, made it bigger than the drag and drop object and then pinned it to it, but this leads to a whole bunch to other problems. When a drag starts for the invisible sprite, I first have to pick the corresponding opaque sprite bellow it by comparing an instance variable that I have set to both sprites, then I have to unpin it from the original opaque sprite, then pin the opaque sprite below to it, and reverse all those actions when the invisble sprite is dropped. The major problem is that picking does not seem to work the way it should, I've experienced a lot of troubles with the picking action so far. Adding to that, setting up an invisbile sprite would double the amount of sprites and make the FPS drop significantly.

- Is there any way to set up the drag and drop behaviour so that a drag is being initiated when the touch (or click) does not happen in the collision polygon only, but in the collision polygon resized by some factor? Maybe there is a plugin? That would solve it all.

- If you have any other ideas, please tell me. :)
B
21
S
9
G
2
Posts: 128
Reputation: 3,001

Post » Thu Jan 05, 2017 3:38 am

put the invisible sprite in a container with the drag/drop object.
The invisible sprite will do everything the object does (and vice versa), including picking.

Yes, this means you have an invisible sprite for every single drag/drop object, but that shouldn't cause your FPS to drop significantly, if at all.


EDIT: I'd still do it the way I said above, but another way, which is closer to what you asked for, would be like:

on touch
pick nearest drag/drop object to touch.x, touch.y
check the distance between the touch and the drag/drop is not too much
and then initiate the dragging that way.
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Thu Jan 05, 2017 3:58 am

I've had the same issue myself. You'll want to use the container method @spacedoubt stated above. Using the second method causes trouble if you have a lot of sprites.
B
62
S
20
G
56
Posts: 1,077
Reputation: 36,021

Post » Thu Jan 05, 2017 3:59 am

If you show the events that give a picking issue we may be able to expain what's going on.

Otherwise here's my first idea:
Just have your tiny sprites and give them the drag drop behavior. Then do one event to do this:

On touch
Pick Sprite closest to touch.x, touch.y
--- Sprite: set position to touch.x, touch.y

That would move the Sprite to where you touched, and I'm taking a guess that might let it start dragging. If not then scrap that idea, but if it works you could use a pick by comparison to pick only sprites within a radius.

Your drag n drop and pin idea sounds like it should work, but I'd have to test it otherwise I can't predict what it would do.

An alternate idea would be to not use the dragdrop behavior and do it with events.

global number obj=-1

On touch
Pick Sprite by comparison distance(Sprite.x,Sprite.y,touch.x,touch.y)<64
Pick Sprite closest to touch.x, touch.y
--- set obj to Sprite.uid

Is touching
Pick Sprite by uid: obj
--- Sprite: set position to touch.x, touch.y

On touch released
--- set obj to -1


That should work. Now you can also save the xy offset when you touch and use that when setting the position to keep the relative offset.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Fri Jan 06, 2017 2:44 pm

Thanks for the advice! I'll do some tests and let you know whether it worked.
B
21
S
9
G
2
Posts: 128
Reputation: 3,001

Post » Sat Jan 07, 2017 4:59 am

1. Tried the idea with the containers. Sadly, you can't put a sprite family and a sprite in a container. As the physics engine in my game interacts with the drag'n drop behaviour, I have to work with families. Besides that, I'd still have to pin and repin the objects in the container... or maybe I'm not getting your point about using a container?

2. Tried the idea of picking nearest objects to touch position and set them to touch position. Works! Now there's only one minor problem left:

How do I pick the nearest object to a point? Can't use min() in that case.
B
21
S
9
G
2
Posts: 128
Reputation: 3,001

Post » Sat Jan 07, 2017 6:20 am

The "pick closest" object condition does that.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Sat Jan 07, 2017 5:53 pm

Ah, I see. I was searching under 'System', not under the object itself.

Alright, Problem solved. 8-)
B
21
S
9
G
2
Posts: 128
Reputation: 3,001


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests