[Fixed] Create sprite between 2 sprites in same family?

Get help using Construct 2

Post » Fri Jul 07, 2017 11:28 pm

How can I create a new sprite half way between 2 sprites that are in the same family by referencing the family?

Example: Create object between Family member 1 and Family member 2
Last edited by Moot on Sun Jul 09, 2017 5:26 am, edited 1 time in total.
B
16
S
7
Posts: 190
Reputation: 1,823

Post » Sat Jul 08, 2017 10:09 am

Use local variables to temporally store values from picked objects.

Pick 1, store the position in local variables, 'x1' and 'y1'
Pick 2, store the position in local variables., 'x2' and 'y2'

(cartesian)
Middle X = x1 + ((x2 - x1) / 2)
Middle Y = y1 + ((y2 - y1) / 2)

(or polar)
a= angle(x1,y1,x2,y2)
d = distance(x1,y1,x2,y2)

Middle X = x1 + ( cos(a) * (d/2) )
Middle Y = y1 + ( sin(a) * (d/2) )

Create object on Middle X and Middle Y.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jul 08, 2017 9:52 pm

99Instances2Go wrote:Use local variables to temporally store values from picked objects.

Pick 1, store the position in local variables, 'x1' and 'y1'
Pick 2, store the position in local variables., 'x2' and 'y2'


Thank you for the response, 99Instances2Go. There's 7 members in the family, so about 21 different combinations. I was hoping to use a family to avoid writing so many events.
B
16
S
7
Posts: 190
Reputation: 1,823

Post » Sat Jul 08, 2017 10:37 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Jul 09, 2017 2:36 am

99Instances2Go wrote:https://www.dropbox.com/s/1wd5snjgedsbxje/UseFamilysForPicking.capx?dl=0


You are awesome! Not exactly what I was asking for, but exactly what I needed. I flipped the compare two values of A.A_id = B.B_d to being unequal and removed lines 3-11 and it worked like a charm. There's only going to be 2 of the sprites on the screen at once and never the same two, so this works great! And in only 2 events. :)

Very clever using two families. I was thinking about only using one. My line of thinking was way off. Thank you for the example!
B
16
S
7
Posts: 190
Reputation: 1,823


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, GrogIsGood, plinkie, rayolf and 6 guests