bevy_tilemap icon indicating copy to clipboard operation
bevy_tilemap copied to clipboard

Example of spawning off-screen chunks

Open ndarilek opened this issue 3 years ago • 1 comments

I'm prototyping a concept where the overmap is much larger than the visible map, and is made up of chunk types. Some distance from the map edge, I want to generate adjacent chunks off-screen, add them to the map, and potentially spawn in enemies/items/etc. I'd like to spawn chunks a bit away from the character, to allow for things like enemy troops to spawn a chunk or two away and advance on the player's position if they are detected. So it wouldn't be just-in-time, but maybe a screen or two of tiles.

Is there an example of this? I'm not thinking it has to be complex--just take the random world example and spawn in adjacent off-screen chunks.

In the meantime, I'm curious about how this currently works. Does autospawn just handle creating the chunks for me from a group of tiles, or does it detect when the camera is about to move off-screen and create a new chunk? I'm not sure whether the current chunk events are meant to tell me that I should run my map generators and create/add a chunk myself, or if it's up to me to detect when a new chunk is needed and do that myself.

Thanks.

ndarilek avatar Jan 20 '21 19:01 ndarilek

There is a sort of example of this with the redo of random_dungeon. I also just opened up the API on tilemap so that you can access to .events() which will allow you to see when chunks are created / despawned, allowing for stuff to be spawned in upon chunk creation if it needs to be. Otherwise, if the chunk already exists, then it will already have the data from before.

joshuajbouw avatar Jan 21 '21 05:01 joshuajbouw