Sorted Picking

This forum is currently in read-only mode.
From the Asset Store
A master sorting Puzzle fun and addictive puzzle game! A challenging yet relaxing game to exercise your brain!
  • hi,

    what is the most efficient way to pick sprites in a sorted manner?

    i've got another fake z-depth scenario that does not handle well with a lot of objects, probably due to bad loop management. here is the cap, in a nutshell: i want to create the illusion of skyscrapers by stacking rectangles (floors) onto each other. currently there are sprites for the bottom & a number of sprites for the floors (the bottoms are invisible). the sorting works like this:

    1) pick each bottom, one after another, sorted by their y-position

    2) pick all floors belonging to that bottom (by comparing a private variable)

    3) pick each of these floors, one after another, sorted by their intended height (another private variable)

    4) put that floor into position & send him to front

    like this, it works mostly correct (few glitches): the top floors are covering the lower floors, and the closer skyscrapers cover the ones further away. but adding more skyscrapers drastically impacts the framerate (my laptop drops <60 with 100 bottoms and ~800 floors). i suspect that the three nested loops are responsible, blowing through ( bottoms * floors(all) * floors(selection)) = 640k iterations each frame.

    sooo... any ideas on a more efficient approach? anything i can think of using other objects (arrays?) hits the bottleneck of picking the corresponding sprite after the sorting. any help would be welcome!

    (otherwise i'd have to scale down from downtown to suburbia ;))

  • For each object (ordered) under System sounds like what you want.

  • people looking at the cap is what i want :P

    but yes, that's what i am currently using. i was just wondering wether there was a more performant way of doing it, because 3 nested loops each looking at every object are a bit slow.

    i just tested to see wether picking objects by use of the ObjectPairer was faster than by comparing private variables, and it appears to be. so that's a start ...

  • I didn't have Construct handy earlier; so I couldn't check your current system.

    I can't really see a better way to do it, but it runs well on my crappy laptop. What sort of numbers were you trying?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i am running into problems (aka below 60fps) when there are ~60 skyscrapers with 8 floors each, like here. thanks for having a look, rich!

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