How do I pick array X values without using for each

0 favourites
  • 5 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • 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!

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

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • jojoe,

    Thanks for your reply! I'm already using Array's for each, but thank you anyway. No worries!

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