How do I Snap Item to Containers

Get help using Construct 2

Post » Thu Jan 08, 2015 10:16 am

Guys, I want to snap the item to the container (shown below)
Image

When the item is on the container, it can be dragged back to its previous place.
The items can be re-arranged on to different containers.

I try to use trash tutorial (on tutorial section) but it's not enough (the item is destroyed after overlapping to the right trash can, which is not what I want). Then I add a boolean instance to the container to act as container's status : 1 for "reserved" (the item is placed on it) and 0 for "empty". But didn't work well.

How's the best logic approach? :?

Thanks for helping :D
B
7
Posts: 5
Reputation: 269

Post » Thu Jan 08, 2015 11:23 am

Sounds like you already have the snapping logic? Also sounds like you have the right idea with the boolean. So unless you want to share your .capx, it's guesswork :)

edit: ok try this. BTW I used an number not a boolean, just personal preference.
container_snap.capx
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Fri Jan 09, 2015 7:56 am

This is the screenshoot. Please wait until I figure out how to attach capx -_- (and I will try to learn from your capx now)

Image
B
7
Posts: 5
Reputation: 269

Post » Fri Jan 09, 2015 8:17 am

I see now. The big difference between my code and yours is that the usage of "DragDrop" events.
I firstly don't understand which one to use, is it "DragDrop drop" or "DragDrop start".

Thanks a lot, Codah. :D
B
7
Posts: 5
Reputation: 269

Post » Fri Jan 09, 2015 9:41 am

Well 'start' is when the object is starting to be dragged, and 'drop' is when it's released. Simply I have a variable on each container instance to specify if something was dropped on it ('taken') that is set to 0 when an item is dragged off it, and to 1 when an item is dropped on it. The xpos/ypos thing is just so if you drop an item on a 'taken' container, we know where it came from so we can put it back there.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: jezjones24 and 29 guests