I’ve been implementing a chunking system for my 2D game, so that I can load only part of my huge world at once. The problem I’m having is transitioning my current rendering code to one that can actually work with a world bigger than the screen. My current code draws everything relative to the screen (the Tilemap is the size of the screen), and I need to draw things relative to the world so that I can scroll around it, as it is much bigger than the screen.
To start, I’m having trouble figuring out how to size the Tilemap. What I’d like is to load every chunk surrounding the chunk that the player is in, meaning there are 9 chunks loaded at all times, and 3 get unloaded/loaded whenever needed. To have them loaded at all times, would I size the Tilemap to the size of 3 chunks x 3 chunks?
And for scrolling, would I just move the Tilemap around? But if I do that, won’t the edge of the Tilemap eventually be reached? Is it the camera (screen) that should be moving, or the world (Tilemap)? Should the Tilemap be the size of the whole world? But then wouldn’t that defeat the purpose of chunking (loading only what’s needed)?
Sorry for having so many questions, I just can’t seem to find definite answers anywhere.
To try and summarize, here are the 3 main questions I have:
How do I size the Tilemap to allow for clean loading/unloading of chunks?
How do I update the Tilemap when loading/unloading occurs?
What is it that I move to scroll, the camera or the world?
Thanks for any insight.