# Object Count

0 favourites
• 24 posts
From the Asset Store
Be quick and count the cards and choose the right number!
• I want that when 3 balls of the same color to touch are destroyed for example, but if two balls touch are not destroyed. And they are destroyed at once.

I tried Count.object but does not work. Any tips?

<img src="http://i61.tinypic.com/kciarn.png" border="0" />

• I've been looking at this on and off throughout the day, and it's definitely difficult with C2s overlap mechanism. I'm wondering about scope: how many unique objects do you have in mind? If you could attach unique hidden objects per colour, you could detect against them, instead of the objects directly.

• You need to use recursion to solve this. Here is a capx

https://dl.dropboxusercontent.com/u/30864403/overlap.capx

Probably not the most efficient way, but this is the idea.

In this example, you can drag the objects around until they overlap. The opacity of the objects will change if 3 or more are touching in any sort of formation (e.g. they don't all have to touch each other, just a series of 3 touching).

Instead of destroying the objects, I make their opacity 50%, for demonstration purposes. You can destroy them if you just change that action yourself.

Disclaimer: There may be bugs :P

• blackhornet:

Say I have 4 balls:

<font color=blue>- Blue </font>

<font color=red>- Red</font>

<font color=green>- Green </font>

<font color=yellow>- Yellow </font>

And only destroy hitting the blue ball with the blue, but in this example you wanted three blue balls collide and are destroyed.

Juryiel: Thanks for the example, I think I can modify it to my liking.

• Well, collision isn't made for 3 objects at a time, so it's not easy this way.

I would start by making an "evalSystemState" function, that would eval the system every 0.1s or so. It would examine every ball, one after the other, checking how many other balls were in its vicinity and saving this in a variable on the balls. Once this is done, you would just have to destroy every ball that have 2 or more in this variable.

• Well, collision isn't made for 3 objects at a time, so it's not easy this way.

I would start by making an "evalSystemState" function, that would eval the system every 0.1s or so. It would examine every ball, one after the other, checking how many other balls were in its vicinity and saving this in a variable on the balls. Once this is done, you would just have to destroy every ball that have 2 or more in this variable.

The problem with that is that if Ball B is in the vicinity of Ball A, and Ball C is in the vicinity of Ball B but NOT in the vicinity of Ball A, then you won't destroy all of the balls when in fact you should (if I understood correctly what the OP wanted).

On the other hand, if the only condition that destroys the balls is when all 3 are touching each other, the problem becomes much simpler, as you say.

As far as doing the detection of one object with multiple objects of the same type, the trick I learned in C1 was to put object A in family A, then pick a given instance of object A, and check it against all instances of family A (except itself). Seems like it works in C2 as well, though I'm not sure if there's a better method.

• I try to do the example Guizmus? or I'll take yours?

• cesarzevil like Juryiel said, you must first decide if a ball between 2 other same balls should or not be destroyed, even if those 2 other balls don't touch themselves.

• if yes, then the method I described should work nicely
• if no, then it's more complicated, you would have to store the Ball.UID of all touching balls, not just the count, and then check if those are next to each other or not.
• when I throw my ball and colliding with two other balls of the same color are destroyed, but then for example there is a total of 6 red balls, and I shot a kill three, then threw another and destroy the other 3. Total destroyed 6 red balls.

I did not know it was so complicated ... I'm about to leave: S

• You're not being very clear about what you want. Think of all the situations all balls on a layout may find themselves in, and describe what you want to happen.

And specifically, if my example isn't doing waht you want, why? What did you need to be different?

• Your example is perfect, but I want to touch the three destroyed sprites and sprite is created, but in doing so, I create three sprites <img src="smileys/smiley36.gif" border="0" align="middle" /> <img src="smileys/smiley36.gif" border="0" align="middle" />

• Sorry still confused, you want to first destroy 3 sprites, then create a single other sprite in their place?

• exact <img src="smileys/smiley4.gif" border="0" align="middle" />

• ## Try Construct 3

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

Construct 3 users don't see these ads
• This means you will need to identify the different groups of overlapping objects within the "Check Overlap" function. A given group can be defined whenever you reach these two conditions:

1. For a given Sprite, there are no more overlapping Reds, (or Sprite2 and Greens) and recursion has reached the deepest level

AND

2. The number of overlapping sprites found is greater than 2

So whenever these conditions are true you can store an X and a Y value of where you want the new sprite to be created, then loop through all those values after they have all been created and create a sprite for each.

Why don't you give it a shot, it should be obvious where the two conditions I mentioned are met if you look at my capx. If you can't figure it out I'll edit the example, but it will be a long while before I have time to do that.

• You can make me your Capx example? <img src="smileys/smiley24.gif" border="0" align="middle" />

• 24 posts