loop efficiency

0 favourites
  • 7 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • I assume it is more efficient to filter objects, then in a sub-event use a for each loop on those picked?

    can anyone confirm this is what is happening? or is For Each always picking all? Is using it in a sub-event less efficient?

    i.e. Let's say I only want to do something to sprites within a specific X/Y Every Tick. I need to do a For Each, but if I have 500-600 sprites, it starts to get heavy. If I filter those sprites to only objects that I need, in a specific region of the layout - will that run more efficient?

    I'm working with a minimap (so I have objects in the entire layout and then all those objects indicators on the HUD). I only need to represent what is the player's range

  • Yes filtering will reduce the number of instances in the sol, as long as it's used before the loop.

    However you should try doing a instance variable comparison before commiting to a for each.

  • newt do the 'for each' in a sub-event of the instance var comparison or at the same level?

    I always thought sub-event were less efficient.. someone somewhere once said.. although maybe I misconstrued that...

  • Instance variables are good for filtering, so yes they go first.

    There's no reason for sub events to be less efficient. It's what you do with the cpu that causes issues, usually loops.

    You may not even need the for each, depending of what the action is.

  • newt awesome thanks, that seems to work pretty good.

    I use a for each only because I am setting each one to a different position. its a minimap/radar thing, and all object outside the player's range can be ignored because I set them invisible in another event.

    the object and the indicator are in a container

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would say, start by picking all the objects in range by "pick by evaluate". If you really need the for each (first try without), then you can do that inside the pick by evaluate as a sub event.

    you can check out my tutorial on a city builder game, where for instance, in a certain part of the code I need to asses the capacity of an asset, and I first pick all of the assets that apply using pick by evaluate and then loop through them to call a function for each of them.

    youtu.be/ygTXlrdpma0

    What you should definitely not do is just loop through them, and then evaluate a condition. Always pick. And avoid doing so on every tick, try and do it triggered.

    Hope that helps

  • Answer your own performance questions with measurements. It's easy to speculate but measurements are the only authority on performance advice. Otherwise you could spend ages fiddling with things that either make no difference at all, wasting your time, or actually make things worse.

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