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
46
S
19
G
3
Posts: 105
Reputation: 4,634

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.
"The intent is to provide subscribers with a sense of pride and accomplishment for unlocking different features...."
B
42
S
18
G
32
Posts: 818
Reputation: 20,779

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
46
S
19
G
3
Posts: 105
Reputation: 4,634

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.
"The intent is to provide subscribers with a sense of pride and accomplishment for unlocking different features...."
B
42
S
18
G
32
Posts: 818
Reputation: 20,779

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
99
S
35
G
20
Posts: 438
Reputation: 17,960

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
133
S
54
G
24
Posts: 799
Reputation: 24,306

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
42
S
16
G
6
Posts: 544
Reputation: 7,701

Post » Sun Mar 05, 2017 8:41 pm

Thanks guys helpful solutions :)
B
46
S
19
G
3
Posts: 105
Reputation: 4,634


Return to How do I....?

Who is online

Users browsing this forum: ultrafop and 0 guests