How do I Snap Item to Containers

0 favourites
  • 5 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Guys, I want to snap the item to the container (shown below)

    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

  • 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.

    [attachment=0:45lriapu][/attachment:45lriapu]

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

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)