Count sprites within a small area

0 favourites
  • 9 posts
From the Asset Store
Be quick and count the cards and choose the right number!
  • 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.

  • 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?

  • 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   <img src="smileys/smiley4.gif" border="0" align="middle" />

  • 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.

  • 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!

  • SpawnExample_BHT139.capx Comments included.

  • blackhornet, thanks very much for the help! <img src="smileys/smiley4.gif" border="0" align="middle" />

  • 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.




  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hey CJK, sorry for the late reply, I haven't been on the forum for a while!

    Thanks for the example, looks really useful   <img src="smileys/smiley20.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)