Do unmet conditions reduce performance of loops?

Discussion and feedback on Construct 2

Post » Tue May 31, 2016 5:33 pm

I have a few "for each" loops, and I also have a condition to check whether or not a tween is still running. If the tween isn't running, would this improve performance, or does the game still have to check the "for each" loop? Is there a way of disabling loops when an instance of an object is no longer needed to be tested (in this case, I have for each loops to make play sound effects , but when the sprite isn't moving, it wont move any more, so the loop testing will no longer be necessary).
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Tue May 31, 2016 9:06 pm

if you have something like this:
-check if tween runing
- then for each .. bla bla

it will not run the foreach loop if tween is not running.

if you have:

- for each ... bla bla
- if tween is running... then bla bla

then foreach will run every time, and you will check if tween is running multiple times.
i can provide more info if you show some kind of code / capx
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
42
S
14
G
12
Posts: 624
Reputation: 9,421

Post » Tue May 31, 2016 9:37 pm

Also, you can put your loops inside groups and enable/disable them when needed.
B
135
S
33
G
17
Posts: 1,557
Reputation: 20,715

Post » Tue May 31, 2016 10:00 pm

glerikud wrote:Also, you can put your loops inside groups and enable/disable them when needed.


Groups or Boo
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
29
G
22
Posts: 1,984
Reputation: 19,997

Post » Wed Jun 01, 2016 9:31 pm

I'm actually wondering this, too (I still don't think this has been answered properly). I end up doing for each checks on things all the time and I certainly notice my CPU go up, but I'm never sure if that's really the cause.
B
40
S
12
G
1
Posts: 532
Reputation: 4,147


Return to Construct 2 General

Who is online

Users browsing this forum: David181 and 10 guests