How can I compare two instances of a same sprite?

Get help using Construct 2

Post » Sun Mar 05, 2017 4:36 am

How can I compare two instances of a same sprite?
like if Sprite.X > Sprite.X
B
45
S
19
G
3
Posts: 102
Reputation: 4,598

Post » Sun Mar 05, 2017 4:58 am

if Sprite(0).X > Sprite(1).X

compares instances 0 and 1.

Note: You CAN'T do this automatically. Autocorrect would only be able to get 'Sprite.X' you really HAVE to go back and retype the "(number)" part.
Image Image Image
B
29
S
11
G
27
Posts: 729
Reputation: 16,995

Post » Sun Mar 05, 2017 5:24 am

I have 100 of that sprite and i wanna check the distance of all of them with each other, so if the distance of one of the instances is less than 50 with another instance something happens to them.
How can i do the above scenario?
Last edited by HessamoddinS on Sun Mar 05, 2017 8:41 pm, edited 1 time in total.
B
45
S
19
G
3
Posts: 102
Reputation: 4,598

Post » Sun Mar 05, 2017 5:52 am

HessamoddinS wrote::twisted: I have 100 of that sprite and i wanna check the distance of all of them with each other, so if the distance of one of the instances is less than 50 with another instance something happens to them.
How can i do the above scenario?


Loop each instance to detect distance w/ respect to other instances.
Look at how loops work first.
Image Image Image
B
29
S
11
G
27
Posts: 729
Reputation: 16,995

Post » Sun Mar 05, 2017 6:56 am

@HessamoddinS

the way I usually do what you want is to put the sprite in a family. Then you can compare an instance to the family

spritefamily.x > sprite.x would then pick all the instances with an x greater than the one you are interested in

and then you can do a for each spritefamily to compare them individually to sprite... or whatever else you want.
B
94
S
33
G
20
Posts: 438
Reputation: 17,615

Post » Sun Mar 05, 2017 10:02 am

AllanR wrote:@HessamoddinS

the way I usually do what you want is to put the sprite in a family. Then you can compare an instance to the family

spritefamily.x > sprite.x would then pick all the instances with an x greater than the one you are interested in

and then you can do a for each spritefamily to compare them individually to sprite... or whatever else you want.


Ditto that. Yes use family, easy and simple.
ImageImage
B
102
S
46
G
22
Posts: 773
Reputation: 21,595

Post » Sun Mar 05, 2017 5:41 pm

You can also use a loop like @MPPlantOfficial said, here's a couple of implementations from @Colludium and @blackhornet that might help:

viewtopic.php?f=147&t=187812
B
38
S
16
G
6
Posts: 537
Reputation: 7,582

Post » Sun Mar 05, 2017 8:41 pm

Thanks guys helpful solutions :)
B
45
S
19
G
3
Posts: 102
Reputation: 4,598


Return to How do I....?

Who is online

Users browsing this forum: bluesun66, Kenthria, Malhog, plinkie, Yahoo [Bot] and 1 guest