How do I count numbers of sprites overlaping X object

Get help using Construct 2

Post » Fri Aug 25, 2017 11:51 am

@99Instances2Go Thanks for the example! May I ask 2 questions about your capx?

1. why do you use a blank subevent under "start of layout"?
2. In subevent 4 I see "if sprite.row = loopindex" and "if text.row = loopindex". What does this do? It seems that the example also works without these 2 lines?
B
27
S
6
G
7
Posts: 678
Reputation: 5,651

Post » Fri Aug 25, 2017 12:19 pm

Blank = same as 'Every tick'. For me, that way the events read better. And they are 'collapsable' to 1 line. Less mess.

They pre-calculate the situation for those 3 blocks that are set in the layout, the set up does not start with no blocks selected, there are 3 blocks pre-selected.
Now, there are 2 rows. I could have done it with 1 event using sprite.row = 0. And then duplicate those evens and change sprite.row = 1 for the other row. But that are 'Duplicates' for a minor change. Duplicated events (and if one does that a lot) makes up for more events. While it should be efficient: as less events as possible.

You can do this by calling a function to the same code, using row as a parameter. That is the main reason for using a function: eliminate duplicated events.

I opted for a repeat loop. Loopindex is the current iteration of the loop. The repeat performs those evens twice. That first time loopindex = 0. The second time loopindex = 1. So the first time it picks the first row, the second time the second row. It looks for selected blocks only in that row, and calculates the sums.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Aug 25, 2017 3:44 pm

If you are working with multiple Sprites, it's harder. Easier way is set animations and put there single sprites or anims. Then you can create ONE simple Boolean for the sprite. If active - set 1. Simple. Then you can put a command in your sheet = Pick all -> IfActive = 1 -> Write it to the text. Dunno what else you can do except what guys up there told you. I am still trying to improve my skill to get better performance with less code. :) I wish you good luck with all of this! :)
SoftWork Group Ltd

Co-founders:
Robert Matik (UK Division)
Lukas Zyrek (CZ Division)

07399443703 (UK Division)

International(at)softworkgroup.wtf - for basic questions and information
Office(at)softworkgroup.wtf - email for questions about team and proposals
B
16
S
5
G
1
Posts: 49
Reputation: 1,656

Post » Fri Aug 25, 2017 3:49 pm

@99Instances2Go Oh great! Thanks for the help and explanation!
B
23
S
10
G
3
Posts: 545
Reputation: 4,442

Previous

Return to How do I....?

Who is online

Users browsing this forum: luckyrawatlucky, Yahoo [Bot] and 20 guests