Count sprites within a small area

Get help using Construct 2

Post » Fri Sep 27, 2013 5:07 pm

Hi all,

I'm spawning small clusters of sprites, at random points across my layout. The number of sprites spawned in each cluster is also random.

I want to work out where the the largest clusters are created, and spawn new sprites there.

Is there a way I can count to see if a cluster contains more than 20 sprites, so that I can tell which are the largest groups?

Thanks for any advice.
B
18
S
4
G
2
Posts: 77
Reputation: 1,588

Post » Fri Sep 27, 2013 5:44 pm

You could assign your sprites an instance variable based on where they spawn (like sprites that spawn at this cluster get ClusterID=1 or something).

Then you could have an event that picks all the sprites with a certain instance variable, and you can use the expression Sprites.PickedCount to get how many of them there are.

Would something like that work?
B
11
S
2
Posts: 87
Reputation: 1,112

Post » Fri Sep 27, 2013 6:07 pm

@Wertle, thanks for your reply, but I'm not sure it would work!

The clusters are spawned at random points all over the layout, and they each contains a random number of sprites.

As I cannot predict where a cluster will be spawned, it might be hard to assign it a value based on its position!

Thanks anyway   
B
18
S
4
G
2
Posts: 77
Reputation: 1,588

Post » Fri Sep 27, 2013 6:12 pm

Do you have a .capx you could share? It might make it easier to devise a solution to see exactly how you're spawning things.
B
11
S
2
Posts: 87
Reputation: 1,112

Post » Fri Sep 27, 2013 6:35 pm

@Wertle, here's a very rough example of what I'm doing SpawnExample.

So sprites are randomly created across the layout, and because of this some spawn in similar locations, creating clusters.

I'd like to test small areas across the layout, to see which contain the largest clusters!unplugged2013-09-27 19:10:12
B
18
S
4
G
2
Posts: 77
Reputation: 1,588

Post » Fri Sep 27, 2013 9:15 pm

SpawnExample_BHT139.capx Comments included.
ImageImageImage
B
71
S
22
G
248
Posts: 3,758
Reputation: 138,067

Post » Sat Sep 28, 2013 7:51 am

@blackhornet, thanks very much for the help!
B
18
S
4
G
2
Posts: 77
Reputation: 1,588

Post » Sat Sep 28, 2013 1:12 pm

Hi @unplugged

As I once had a need for this, too, I just tried a more visual approach, where the neighborhood is determined by a collision area of a shape.

pick_dense_neighbourhood.capx

Cheers,
Greg
B
18
S
3
G
3
Posts: 83
Reputation: 3,736

Post » Wed Oct 23, 2013 9:43 am

Hey @CJK, sorry for the late reply, I haven't been on the forum for a while!

Thanks for the example, looks really useful   
B
18
S
4
G
2
Posts: 77
Reputation: 1,588


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests