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
112
S
42
G
31
Posts: 1,188
Reputation: 29,747

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
172
S
50
G
189
Posts: 8,510
Reputation: 118,739

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
112
S
42
G
31
Posts: 1,188
Reputation: 29,747

Post » Sun Jan 31, 2016 6:29 pm

Families also help solve this kind of problem.
ImageImageImage
B
71
S
22
G
267
Posts: 3,807
Reputation: 147,745

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
112
S
42
G
31
Posts: 1,188
Reputation: 29,747

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
71
S
22
G
267
Posts: 3,807
Reputation: 147,745

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
112
S
42
G
31
Posts: 1,188
Reputation: 29,747


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests