How do I count numbers of sprites overlaping X object

Get help using Construct 2

Post » Wed Aug 23, 2017 3:49 pm

How i can show in the Text object how many Sprites with a Instance variable: Active: 1 are overlapping the red line?

Image

I actually do this:
For each Text Object
Sprite Value=1
Sprite Overlaping RedLine >> Set Text to Sprite.PickedCount

Works but is CPU intense, and having lots of lines get my CPU at 80%. The sprites are activated to White/Green on mouse click. I tried "On any mouse click" and do a function that does this but not works.

The sprites are static and the line always pass over the same ones.

How can i fix it?
B
23
S
10
G
3
Posts: 545
Reputation: 4,442

Post » Wed Aug 23, 2017 4:16 pm

The intensive CPU usage is because you're updating the text object every tick I guess. You should avoid doing this where possible. The logic itself seems fine.
B
46
S
16
G
73
Posts: 2,084
Reputation: 43,677

Post » Wed Aug 23, 2017 4:33 pm

Well, thats the problem, i tried using a function to when is call execute this one time or just update on "Any mouse click" then do that, but never updates ¿?
B
23
S
10
G
3
Posts: 545
Reputation: 4,442

Post » Wed Aug 23, 2017 4:38 pm

post the code with the function, that makes it much easier to see any possible problem
B
16
S
3
Posts: 67
Reputation: 1,044

Post » Wed Aug 23, 2017 4:50 pm

Post a screenshot of the event with mouse click or function, should work fine...
B
46
S
16
G
73
Posts: 2,084
Reputation: 43,677

Post » Wed Aug 23, 2017 4:57 pm

Here the screenshot:

Image

Instead of a red line i use the TextObject adding a larger area that overlaps the sprites so there are less objects involved.

Without the "On Any click" works perfects but CPU intense. I also added a it on to a funtion and call it with a click or keyboard or whatever and nothing.
B
23
S
10
G
3
Posts: 545
Reputation: 4,442

Post » Wed Aug 23, 2017 9:21 pm

You could try moving the overlapping condition above the variable comparison. But you'll probably get better results from changing your logic.

When do the sprites change? If they only change one at a time you could just update that line instead of all of them.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Wed Aug 23, 2017 10:12 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Aug 24, 2017 8:06 am

99Instances2Go wrote:'Pick all' is what you need.
https://www.dropbox.com/s/rxvhk2pn961av ... .capx?dl=0


Oh! thanks! In my case use an instance variable because can be various numbers and the text object have to show the sum, hope this solution works for my needs.
B
23
S
10
G
3
Posts: 545
Reputation: 4,442

Post » Thu Aug 24, 2017 10:20 am

Well that will not be enough. Easy way:
https://www.dropbox.com/s/lxa131kkffhrb ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to How do I....?

Who is online

Users browsing this forum: JoyfulDreamer, StillSarah and 21 guests