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

0 favourites
  • 7 posts
  • 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% :

    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 ? :/

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

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

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thanks blackhornet !! i love you ! yes, it is more efficient 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 !

  • 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

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

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

    anyway i found a "workaround" wich kinda works, and is a HUGE performance improvement, but doesn't use a function:

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