How do I differ to instances of the same object

Get help using Construct 2

Post » Sun Jan 31, 2016 5:05 pm

Hi,

I want to get the distance between to sprites, but they are the same objects (just copies). I know that I can use two diffrent objects to avoid that, but in my game I have more than 2 copies, and I don't want to create a new sprite for each of that.

The code for example:

Code: Select all
distance(Sprite.X,Sprite.Y, Sprite.X,Sprite.Y)


Is there a way to pick the second instance of the object? The code above returns 0, due to the fact that it doesn't calcualate the distance between the two instances but of its own.

Thanks for your help in advance!

Regards
Andy
Image Image iTunes: Match3 | Google Play: Match3
B
122
S
44
G
31
Posts: 1,203
Reputation: 30,257

Post » Sun Jan 31, 2016 5:51 pm

You can use the iid sprite(iid).x if you know the id's beforehand.
Image ImageImage
B
178
S
50
G
206
Posts: 8,686
Reputation: 127,715

Post » Sun Jan 31, 2016 6:05 pm

newt wrote:You can use the iid sprite(iid).x if you know the id's beforehand.


Ah didn't know that this is possible. I'll try that. Thank you!
Image Image iTunes: Match3 | Google Play: Match3
B
122
S
44
G
31
Posts: 1,203
Reputation: 30,257

Post » Sun Jan 31, 2016 6:29 pm

Families also help solve this kind of problem.
ImageImageImage
B
72
S
22
G
288
Posts: 3,862
Reputation: 158,460

Post » Sun Jan 31, 2016 6:30 pm

blackhornet wrote:Families also help solve this kind of problem.


Thanks for that hint. How do I do that? Do I just use the family.X/Y then?

Thanks!
Image Image iTunes: Match3 | Google Play: Match3
B
122
S
44
G
31
Posts: 1,203
Reputation: 30,257

Post » Sun Jan 31, 2016 6:34 pm

Without more details, it's hard to be specific, but in the worst case you can put all objects in two Families. Then you can do distance(FamilyA.X,FamilyA.Y, FamilyB.X,FamilyB.Y)
ImageImageImage
B
72
S
22
G
288
Posts: 3,862
Reputation: 158,460

Post » Sun Jan 31, 2016 6:38 pm

blackhornet wrote:Without more details, it's hard to be specific, but in the worst case you can put all objects in two Families. Then you can do distance(FamilyA.X,FamilyA.Y, FamilyB.X,FamilyB.Y)


Now I got it! Thank you!
Image Image iTunes: Match3 | Google Play: Match3
B
122
S
44
G
31
Posts: 1,203
Reputation: 30,257


Return to How do I....?

Who is online

Users browsing this forum: Davoo, marks2, signaljacker, sinoscuras and 7 guests