How do I pick the next nearest sprite?

Get help using Construct 2

Post » Thu Jan 26, 2017 11:41 pm

Hi.

I have multiple instances of a sprite, one with a variable number set to 1 while the others are set to 0. I'm trying to pick the instance of the sprite that is closest to the sprite with it's variable set to 1. I tried a few things I saw on other forum posts but none seem to be working.

Basically, this is what I've been trying:

Pick all (sprite)
-Pick (sprite) where variable = 1
--Pick (sprite) nearest to (sprite) --- Destroy

That just destroys the sprite that has a 1 for the value.

Not sure what I'm doing wrong. I guess essentially I want to pick the second nearest sprite.

Any ideas?
Thanks!
B
19
S
7
G
10
Posts: 82
Reputation: 4,996

Post » Fri Jan 27, 2017 12:40 am

Create two local variables, localX, localY

Pick (sprite) where variable = 1
-localX=Sprite.X
-localY=SpriteY
-Pick all (sprite)
--Pick (sprite) where variable = 0
---Pick (sprite) nearest to (localX,localY) --- Destroy
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Fri Jan 27, 2017 4:11 am

@blackhornet

Brilliant! Works great.

Thanks a lot for taking the time :)
B
19
S
7
G
10
Posts: 82
Reputation: 4,996


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests