Drag and Drop Nearest

Get help using Construct 2

Post » Tue Nov 12, 2013 6:23 pm

Hi
I have a sprite for my board game and 9 positions that it can go on top of. I am using drag and drop but am struggling to drop the piece on one of the 9 defined cells rather than a gap in between. I would like the piece to be snapped to the nearest cell that it can go on when dropped - should I be using pick nearest in some way?

Any help gratefully received!

Thanks
Matt
B
12
S
3
Posts: 37
Reputation: 1,111

Post » Tue Nov 12, 2013 6:24 pm

Pick nearest object: set sprite position to object.x, object.y

Object is one of the places where it can be dropped
Sprite is the thing you dragged

If you only want it to snap only when the distance is less than some value, add

distance(object.x,object.y,sprite.x,sprite.y) < yourvalue

as a condition.mindfaQ2013-11-12 18:27:56
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Tue Nov 12, 2013 7:03 pm

Thanks for the help - it's very useful. I've tried that but the sprites either don't snap or end up on top of each other at one place (snapped). I think I may need to specify a particular cell somehow.
B
12
S
3
Posts: 37
Reputation: 1,111

Post » Tue Nov 12, 2013 7:14 pm

Are there any pick nearest/touch examples at all?
B
12
S
3
Posts: 37
Reputation: 1,111

Post » Tue Nov 12, 2013 8:04 pm

http://s000.tinyupload.com/index.php?file_id=09200354917869756127


edit:
this one above had a bug, it is fixed here:
http://s000.tinyupload.com/index.php?file_id=78619334152685043969
edit: need to set the default value for occupied_field to -1mindfaQ2013-11-12 20:19:56
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Wed Nov 13, 2013 8:26 am

Thanks very much! I've managed to get the counters to now drop into place.
B
12
S
3
Posts: 37
Reputation: 1,111


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, dop2000, evillair, Fenix18, tarek2 and 51 guests