How do I optimize position checks for many instances

0 favourites
  • 2 posts
From the Asset Store
Vector illustration of a UFO with an alien in three different positions.
  • Hi, I'm making something with a large number of generic pick-up items (think coins in Super Mario), several hundreds up to more than a thousand per layout.

    I need to make every instance within a certain area move, but checking each instance is very taxing on performance with mobile devices. It appears to be a bit more efficient to do an "is on-screen" check before comparing the precise coordinates, but it's still getting pretty demanding with larger layouts / higher item counts.

    Are there any tricks to speed this up a little more?

    I was thinking about not putting the object instances in the layout editor but instead load them in chunks when certain areas come on-screen, but then again I'm wondering if creating 50-or-so objects at certain coordinates might also cause slowdown on low-end devices? (Also, if I'm going that route, is there any convenient way to turn a layout into a series of create object actions?)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • OK I found the below method greatly improved performance for me, so I'm posting it for posterity in case someone ever runs into the same issue:

    • destroy all instances of the object(s) in question on start of layout
    • call "Recreate initial" for the object type or family in a specific area once the player gets close to it

    Stuff to be aware of:

    • this works best for games with linear progression where you expect that most or all instances will be destroyed once the player is past them (otherwise performance will suffer the same way as before once all instances in a layout are spawned and not destroyed)
    • make sure Recreate initial is only called ONCE for each area, or you end up with duplicates of the same object stacked on top of each other and/or resetting of areas
    • this messes up z order, so use ordering by layers where it matters.
    • any "for each" type state changes made before entering an area will not affect the instances in that area (cause they didn't exist at that time)
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)