How do I Drag/Drop and Stick To Image Point

Get help using Construct 2

Post » Mon Mar 24, 2014 9:28 pm

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?
B
9
S
3
Posts: 50
Reputation: 804

Post » Mon Mar 24, 2014 10:07 pm

Something like this?

@jmiller4180
(Edit - Okay now it snaps to the nearest image point.)
You do not have the required permissions to view the files attached to this post.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Mon Mar 24, 2014 10:32 pm

Amazing! It is exactly what I was looking for :D , 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?
B
9
S
3
Posts: 50
Reputation: 804

Post » Mon Mar 24, 2014 10:46 pm

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.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Mon Mar 24, 2014 10:54 pm

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?
B
9
S
3
Posts: 50
Reputation: 804

Post » Mon Mar 24, 2014 11:04 pm

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. :ugeek:
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Tue Mar 25, 2014 2:09 am

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.
You do not have the required permissions to view the files attached to this post.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Thu May 15, 2014 8:13 pm

I know this is an old post but it helped me soo much I had to say thank you!
B
3
Posts: 7
Reputation: 189

Post » Fri May 16, 2014 6:38 am

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

Thanks, - V
B
14
S
4
Posts: 190
Reputation: 1,735

Post » Wed May 21, 2014 8:58 pm

@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...
Check out my latest game RAPID-TAPIT. Get your Fingercise on with this one. A steady Tap is all you need to score points. Lift a finger and see what you can do...

Image

ALLMarkMade Designs
B
41
S
20
G
6
Posts: 367
Reputation: 7,541

Next

Return to How do I....?

Who is online

Users browsing this forum: Casaubon, dop2000, max2612 and 5 guests