0 Favourites

How do I Drag/Drop and Stick To Image Point

  • Hello,

    I am working on a project where it entails dragging a circle into a box, dropping the circle and append to the box at the closest image point to circles current location.

    I get the drag, and drop stuff, and I can do that already, but I am having trouble with once the circle is dropped attaching it to the box (so when the box moves the circle remains where it was dropped inside the box), and I also wanted it to drop and attach to the closest image point that the circle is closest to in the box. Sort of like snapping to the image point its closest to in the box once the drop happens.

    Can anyone give me pointers? Or if this is even possible?

  • Something like this?

    @jmiller4180

    (Edit - Okay now it snaps to the nearest image point.)

  • Amazing! It is exactly what I was looking for , could you provide a brief explanation for what is going on inside there so I can add to, or change things around if need be?

  • Sure...

    Line 1 - The event is on drop of the small box

    Line 2 - is a sub event to line 1 and checks to see if you dropped it over the large box

    Line 3 - is a sub event of line 2 and compares the distance between the small box position and ImagePoint(0) and see if it's less than the distance between small box position and ImagePoint(1). If it is I set small box's position to large box's ImagePoint(0) and pin it to large box by position and angle.

    Line 4 - this is also a sub event of line 2 (If there are only 2 image points you probably don't need this, you could just use an Else statement) It checks to see if it's a shorter distance to ImagePoint(1) if it is I set the small box's position to the large box's ImagePoint(1) position, and pin it there.

    Line 5 - Unpins the small box on the start of a drag in case you want to move it after you have dropped it on the large box.

  • Thank you very much, what edits would be made if there are for example 4 image points it could pin to. Imagine it being like a robot you are adding wheels to, 4x image points on the base of the robot, and only those 4 places can hold a wheel because there will be more points for other objects. Do you think I may be better off creating invisieable objects, pinning those to the robot base to start, then pinning the wheels to the objects instead of image points?

  • Hummm.... It might be a good idea to have some invisible sprites pinned to a base that you could then snap things to. It would allow you to name the invisible sprites and then do a pick nearest of the named invisible sprite. Now I need to do some experimenting.

  • Using invisible objects was much easier code. As implemented it will not differentiate between large objects. So if you had two large objects on screen, and if the hidden point on the large object that you didn't drop the small object happened to be nearer it would snap to that one.

  • I know this is an old post but it helped me soo much I had to say thank you!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • WOW!

    Great find. I was looking for this feature too. Snapping a dropped object help is hard to come by.

    Thanks, - V

  • shirokuma will this work with a catch, carry and drop? I need for a falling object to stick to the players hands, carry the object and then drop it.

    Thank you...

  • ALLMarkMade

    That's kind of a different beast, but it can be done. Here is something to get you started. Use the arrow keys to move the player, and use the space bar to drop the prize.

  • shirokuma

    I will give it a shot ASAP thank you so much....

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
217 18,570
humanescape's avatar
humanescape
Unread hot topic
99 10,155
karshinkoff's avatar
karshinkoff
Unread hot topic
56 4,736
MPPlantOfficial's avatar
MPPlantOfficial