In a 2D scrolling platformer, what is the most efficient way or knowing which things with parallax depth should be drawn?
The approach below describes trying to know which things are nearby so they can be udpated/drawn. The problem with working out which parallax items are nearby is that you don't know where any of them are until you calculate where they are!
I have a 2D array
Set<Thing> that I use to store
Things that appear on each screen in a scrolling 2D platformer. I use this to look up only
Things that a near the current location being rendered, so that I don't bother updating irrelevant objects.
I translate the world coordinates, divide them by the screen size (rounding down), and can then look up all the items on that screen. For instance if screens are 320x240px, and I look up world coordinates 400,50 then 400/320 = 1 and 50/240 = 0, so I look up
things and update all the things in that entry. If any object can move, they store themselves in the right slot after moving.
Is there any way to use this same system when
Things have parallax depth? IE, something with a parallax depth of 1 is infinitely far away (and so always appears at the same location in screen coordinates) and something with parallax depth of 0 is pinned to the foreground.
I'm guessing this isn't possible, as something further away than the foreground will be in more than one screen.
What other approaches are there? I've seen an experienced game developer use a 'scroll rate' instead of a parallax depth, and he moved scenery by the inverse of the distance the camera moved multiplied by this rate. In this model I could treat scenery as per any other moving item and have it store itself in adjacent entries in the 2D array when it moves, but how does it get into the 'right' array slot in the first place? IE, if it's very distant, it could be approach from either the left or the right, and I'm not to know that in advance.
I'm very confused!