Pin SpriteA ImgPoint to SpriteB ImgPoint?

Get help using Construct 2

Post » Tue Jul 23, 2013 10:49 am

Hi! I found a few examples how to pin/move objects to another objects image point like this (both lines work):



But is it possible to get a list of available image points of the source sprite to attach SpriteB(2) to SpirteA(1) for example? Right now it seems only the target can have a specific Imagepoint.

For now I just tested it with OnClick and move SpriteB to SpriteA but the ideal solution would be if you could drag & drop objects onto the image points of another object and they would "snap" (and rotate held object with right click for example). So you could snap a cube to a triangle on any of their flat sides together - I hope you can understand what I mean. So can you get the source image points somehow to be able to drag and snap them to the target?

Another alternative would be to click on the source object and then on the image points of the target to attach it there, but you still need to get the image points of the Source sprite to be able to rotate it and attach it to the target properly.
B
53
S
16
G
6
Posts: 718
Reputation: 9,150

Post » Tue Jul 23, 2013 11:57 am

Couldn't you compare the distance of the imagepoints of spriteA to the imagepoints of spriteB and then snap to the closest?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Jul 23, 2013 12:17 pm

Like:
Get SpriteA.ImagePoint.X, SpriteA.ImagePoint.Y
Get SpriteB.ImagePoint.X, SpriteB.ImagePoint.Y
(stored in a local/global Variable?)

If X and Y values are only +/- 10 Pixels apart snap/drop it there and pin it? (need to get the angle for triangles or rotated targets)

I will try if this works when I am back. Thanks for the hint. :)Bl4ckSh33p2013-07-23 12:17:55
B
53
S
16
G
6
Posts: 718
Reputation: 9,150

Post » Tue Jul 23, 2013 12:33 pm

You could just use a system compare two values event for that.
You don't have to store anything in a variable.

system compare values : distance(SpriteA.imagepointx(1),SpriteA.imagepointy(1),SpriteB.imagepointx(1),SpriteB.imagepointy(1)) - is less or equal to - 10

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Jul 23, 2013 3:22 pm

Great idea! But this does not work with multiple points and objects, right? You cant add a loop like "for each point on SpriteA compare if near any point in Working area"?

Let me explain: In the final game you have to select one object with X points (different for different objects) and you can have one or more (!) objects in the working area where you place it which have also the same or different amount of image points. There could be some squares, a triangle and so where the selected object needs to snap on.

So I need to do "For ImagePointCount loops" for all objects and store them in an array to compare all values against the coords of the currently selected item? Or is there an easier solution.Bl4ckSh33p2013-07-23 16:12:04
B
53
S
16
G
6
Posts: 718
Reputation: 9,150

Post » Sun Jul 28, 2013 3:34 pm

I am trying it with an array now. But I could need a few hints from experienced users.

The player can select from several parts and rotate/place them at existing parts in the game to build something with it.

What I have so far (not entirely tested):


Assuming the added parts work as expected the next thing would be to check if Sprite2 (or the currently selected/dragged item) Image Points are +/- 5 Pixels to any other imagepoint (except origin) and if they are they should snap and place the dragged/selected object.

When trying to check if the X and Y points are > 5px or < 5px it seems I have to add many new conditions for it. AND or OR don't seem to work in the expressions?

(e.g. in a "for loop" for each array item but if you have a loop as subevent of a loop, how can you select the loopindex from the first one?)
B
53
S
16
G
6
Posts: 718
Reputation: 9,150

Post » Sun Jul 28, 2013 6:51 pm

Just a quick addition.
If you want to have "sub-hardpoints" for things like equipment or weapons there is no way to get an ImagePoints name, right? So it would be the best solution to add them as instance variable and put the x,y coords for the points there?
B
53
S
16
G
6
Posts: 718
Reputation: 9,150

Post » Fri Aug 29, 2014 9:10 pm

I just did something similar like this, its really quite simple.

For your ship. in the sprite editor add image points all over the ship where things can attach.
Next lets create a dummy sprite that will show up at wherever these attachment points are while the mouse is held down.

Mouse Event (On mouse down AND is touching ship addon part: eg: "lasers")
(Local variable - ShipAttachPoints
System For Each "Ship" -> Set ShipAttachPoints = Ship.ImagePointCount
(sub event) - For "y" from 1 to CountAttachPoints -> Create Object "Attachpoint" at Ship.ImagepointX(loopindex), Ship.ImagepointY(loopindex)
Pin Attachpoint to Ship

This will create attachpoint objects all over your ship at each imagepoint and pin it so that they follow your ship.

Next you need to check how far away the selected piece is to the closest ship attach point, and upon mouse release, snap the pieces together and pin the piece to the attachpoint.

On Mouse Release
Pick Nearest (attach point) (from attachpoint to mouse position)
(subevent) compare 2 values (distance(attachpoint.x attachpoint.y, mouse.x, mouse.y) < 10 pixels
subevent -> set position and angle of ship piece to attachpoint.

voila. The piece will snap to the closest attachment point when you release the mouse.
B
81
S
38
G
14
Posts: 968
Reputation: 16,061

Post » Sat Jan 02, 2016 6:48 pm

justifun or anyone else that understands his solution, can you please post a capx for it?

Thanks
B
8
S
1
Posts: 27
Reputation: 515


Return to How do I....?

Who is online

Users browsing this forum: aramesh and 3 guests