I have a 2D tile based engine with infinite procedural chunk generation.
But I can't invent an algorithm, that will fill only chunk tiles on view port (and destroy old). Pls help
ViewPort size can changing on the fly (2 - 100)
I can't load all chunks completely, because I need to analyze the tiles in the visibility zone
class Map {
public List<Chunk> { get; set; }
public int viewPortWidth = 2 ... 100;
public int viewPortHeight = viewPortWidth;
public Vector2Int playerPosition { get; set; }
}
class Chunk {
Tile[] Tiles { get; set; }
public int chunkWidth = 16;
public int chunkHeight = chunkWidth;
public Chunk(int _leftX, int _bottomY)
{
for (int y = 0; y < chunkHeight; y++)
{
for (int x = 0; x < chunkWidth; x++)
{
randomNumberGenerator.InitState(x + _leftX, y + _bottomY);
chunk[x, y] = randomNumberGenerator.Range(100);
Tiles.Add[chunk[x, y]];
}
}
}