How do I pick array X values without using for each

Get help using Construct 2

Post » Sat Oct 03, 2015 5:35 am

Hi,

I'm using 'for each loop' to pick values of a one dimensional array and copy them to a 2 dimensional array. But the problem with 'for each loop' is that somehow it is slowing down my game FPS on mobile devices (about 15 FPS slower).

I've done some testing disabling the 'for each loop' and the game runs smoothly (60 FPS). So i've tried to figure out how to do the same process without using the 'for each loop', but i couldn't. I've tried 'while loop' but wasn't able to make the copy work properly.

The only noticeable improvement (with the 'for each loop') was made by deleting the current X value of the one dimensional array after copying it to the second array. But it still slowing down the game, although less than before.

So my hope is to get some help on how to do this process without the 'for each loop', to see if the FPS may stand on 60. Any suggestion will be pretty much appreciated!

Thanks!
B
14
S
5
Posts: 110
Reputation: 1,338

Post » Sat Oct 03, 2015 6:46 am

Just as some context, are you doing the for each every tick? I can't imagine any other reason for it being so slow. Literally wherever possible, it is downright necessary to make for each loops only run on triggers or after ensuring you have only picked the right instances / entries first.
B
42
S
14
G
3
Posts: 165
Reputation: 5,115

Post » Sat Oct 03, 2015 1:17 pm

Sumykl,

Thanks for your reply!

I'm not using every tick, just the array loop 'for each X element'. I thought it could be an infinite loop, so after copying the values, i've deleted them to ensure that the array is completely empty and the loop won't continue. As i mentioned, it gave me better FPS, but not good enough. It is strange, and i'm really have no clue what may causing it. So i'm trying to do the same process with different events.
B
14
S
5
Posts: 110
Reputation: 1,338

Post » Sat Oct 03, 2015 2:22 pm

There is an iterate command in C2 that is specially designed for looping through Arrays at light speed. Use the Arrays For each rather than the System For each to save some resources.

If you are already using the Array's for each, i apologies for not understanding. I don't English very well.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Sat Oct 03, 2015 11:08 pm

jojoe,

Thanks for your reply! I'm already using Array's for each, but thank you anyway. No worries!
B
14
S
5
Posts: 110
Reputation: 1,338


Return to How do I....?

Who is online

Users browsing this forum: diamantico21, ratboy3, Yahoo [Bot] and 32 guests