Run a for each loop only for the objects actively on the screen?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Anyway my question is as the title suggests. I want to run a for-each loop for an active object. But i only want to run it for the ones that are currently on screen. Running a for-each loop for every single one of those actives in the level will/is destroying my games performance. Does anyone know how this could be done?

    Fusion Veteran Since 2005. Example Projects: Please login to see this link.

  • Example lets say i had an active named "wall", and there are 100 of them in a frame. But while the player is moving around there are only around 15-20. Is there a way to run a for-each loop that only iterates those 15-20 "wall"s?

    Fusion Veteran Since 2005. Example Projects: Please login to see this link.

  • Glad I could help. If this is strictly for the player to test collisions, you should try using a "Is overlapping" condition to reduce the scope of the foreach loop. ForEach will only run enough loops to cover the the objects that meet the event's conditions. So in the suggestion I made, only objects that are positioned between the left and right of the screen will be checked int he loop. But you can also add conditions for walls inside the y positions of the screen (between y top frame and y bottom frame). My original assumption was you only moved left/right so I didn't include the y position check. But ultimately, if this is simply checking a couple objects against the walls and floors, you should use an overlap check to execute the loop. That way it is only running a couple loops every frame.

    Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!