Side scroller coordinate handling

i was wondering what the best approach would be for a side-scrolling, with wrap-around, world map scenario.

The idea is that my world coordinates go from (i’ll use numbers to make things easier to talk about).

0 ---- 1000

but the screen is displaying the world in chunks as the player moves

center-50 — center+50

with the obvious problem as to how to handle the wrap from 1000 to 0.

There are two ways (and probably more) one could approach this.

1 actually generate a world coordinate system of 0 to 1000, draw everything, and simply move the viewport so that it’s centered at an offset and let the viewport clip everything. Not sure how to handle the wrap around, but i’m sure i can kluge it (two viewports adjacent to each other ?)

2 the other option is to maintain a “logical world” and simply run a search to figure out what’s in the current viewport and then map the world coordinates to viewport coordinates.

I think 2 is the better option and probably what’s generally done for any sort of game scenario. it allows you to maintain sparse collection of objects and do no work on things that are clearly out of the display.

I’m just wondering if there is support in Panda for either of these scenarios before i go and write the code.

thanks!

One way to approach wrap-around viewing, I think, is to duplicate objects near the edges. That is, beyond your “1000” point, duplicate any models and colliders that are near the “0” point, and vice versa.

As to handling large numbers of objects, well, I have two answers there:

First, you likely don’t need to worry overmuch about the models themselves, the actual nodes in the scene-graph: any that are outside of the camera’s view should be automatically culled away by Panda, I believe.

Second, as to the “logical” objects–things like instances of some “enemy” class that handles enemy-AI, and so on–you might divide your game-world into a grid (or a line of cells, if the world only extends along one dimension). As objects move, update which cell they’re contained within–something that primarily comes down to a bit of maths, I believe. Then only update those objects that are in visible cells (again, something that can be determined via a bit of maths), and perhaps those in adjacent cells.

Of course, that’s presuming that you have enough objects present to actually place any real strain on the sort of systems that you have in mind–have you confirmed this, if I may ask?

This game has infinite wrapping (though it’s not a side-scroller):

The trick is, if I recall correctly, to instance the entire world nine times (three times in your case) and have the player always stay in the “middle” world. When your player passes over into one of the “side” worlds, pop it back into the middle one using a modulo operation.

2 Likes

Ah, yes–I think that I’d forgotten about instancing. That would, indeed, be a good way to implement that “duplication” that I described above, I believe!

fairly low number of objects, probably < 100. certainly < 1000.

the funny thing is that a “true” side scroller would be easier because it would have a definitive beginning and end.

the duplication idea is really interesting, I hadn’t thought about that at all.

thanks !

In that case, I’d suggest just trying it the naive way–i.e. just have all the logical objects be present–and seeing how the system handles it. If it proves too slow, then perhaps optimise–if not, then there’s little call for optimisation!

That said, I think that I misread your post as suggesting optimisation, which is my mistake! In which case, just let the above be arbitrary advice! ^^;

i think that’s the way to go. simple implementation, which is easy to understand first, optimization later.

now i have to understand how all this scenegraph stuff works. lol

1 Like

I forget whether I’ve already linked you to this, but in case I haven’t, let me note that I have a “beginner’s tutorial” that goes through the fundamentals of using the engine–including things like the scene-graph.

(That amongst other things–indeed, it goes through the process of making a simple game, from the basics of the engine, through coding the game itself, to building a distributable.)

If you’re interested, you should find it here:

1 Like

I have seen that before and had completely forgot about it.

added it to my Panda links folder!

1 Like