[SOLVED] How do I optimize cpu usage with "For Each" event ?

Get help using Construct 2

Post » Fri Sep 02, 2016 3:09 am

Hey guys i need some help here, i'm making a small puzzle game, it all works nice but i think it uses way too much ressources...
up to 22% of my i5-3570k CPU, i doubt it's normal for such a small game.
It seems that it's caused by all the "for each" events

these simple 2 events below use like 5% :
Image

there are alot of these 2 sprites in each level, if i don't use the "for each" event they don't act separately :/

i searched on the forums/tuts couldn't find anything to replace that...any ideas ? :/
Last edited by nkay on Mon Sep 05, 2016 1:38 am, edited 1 time in total.
B
6
S
1
Posts: 13
Reputation: 380

Post » Fri Sep 02, 2016 3:37 am

If i may are you looping infinite or do you have a previous condition that would make them only move when the condition comes true.

like a trigger event first or if you want you can slap it onto a function and only call it to be use when needed.
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Fri Sep 02, 2016 3:58 am

hey, thx for the fast answer !

it's looping infinite, i wanted to make a trigger like :
when var_red (either of sprite 1 or 2) is changed, then modify each overlapping line colour, but i simply didn't find a way to do it :/ ...the screenshoot is the only way i found to do that :/

i tried with a function...but it doesn't work. here's a screenshoot in case i did it wrong :
Image
B
6
S
1
Posts: 13
Reputation: 380

Post » Fri Sep 02, 2016 4:02 am

The two loops are redundant, in each case you are checking if ligne overlaps ligne2. Regardless of which order you check them, they either overlap or they don't. This should be a bit more efficient.
Image
ImageImageImage
B
71
S
22
G
248
Posts: 3,757
Reputation: 138,065

Post » Fri Sep 02, 2016 4:23 am

thanks blackhornet !! i love you ! yes, it is more efficient :D and it simplifies the scripting ! <3

it still requires alot of cpu ressource but i just need to find the right way to trigger it !
B
6
S
1
Posts: 13
Reputation: 380

Post » Fri Sep 02, 2016 4:30 am

Function is still the way to go. You forgot to make a change happen before the function. Try this Mouse click , overlapping the Ligne then flip it's varable and then call the function.

Because you just simply ask it to start chain reaction when the action hasnt started.

Its like asking the water to jump but you haven't bump the table yet. Function is rather a weird cookie it behave smart but it need a push for it to call just right. especially the for each
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Sat Sep 03, 2016 12:34 am

i'm sorry GearWorkDragon...i don't understand what you mean :oops: i'm a noob ...

i tried this, but it doesn't work, guess it's not what you meant :
Image

anyway i found a "workaround" wich kinda works, and is a HUGE performance improvement, but doesn't use a function:
Image
B
6
S
1
Posts: 13
Reputation: 380


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests