Search code examples
javalibgdxinfinitesimplex-noise

Infinte map generation in isometric game - Java LibGDX


I'm currently trying to learn game developing in Java with LibGDX and have a few questions regarding infinite map generation in an isometric type tile game. My current code in a Screen constructor looks like this.

for (int col = MAP_WIDTH - 1; col >= 0; --col) {
        for (int row = MAP_HEIGHT - 1; row >= 0; --row) {
            int x = (col * TILE_WIDTH / 2) - (row * TILE_WIDTH / 2);
            int y = (col * TILE_HEIGHT / 2) + (row * TILE_HEIGHT / 2);

            float noise = OpenSimplex2.noise2_ImproveX(SEED, ((float) col) * scale, ((float) row * scale));
            mainStage.addActor(new TileActor(x, y, col, row, getNameFromNoise(noise), mainStage));
        }
    }

This adds and Actor in a set MAP_WIDTH and MAP_HEIGHT and changes the texture of that tile depending on a simplex noise algorithm. How would I best go about changing this to an infinite world? Should all the noise values be calculated beforehand and then the actors be loaded when the camera pans over their position? How would i best store this generated map? Thanks.


Solution

  • I don't think you need to store simplex values because its not a random function, you always get the same result for a given input, hence why one of the input parameters is usually time, to get change. Now admittedly I haven't used OpenSimplex2 I used another implementation but the whole point is that simplex noise is -coherent- so it cannot rely on randomness, which isn't coherent. So I assume that you are using SEED to provide a different level every time you play and so assuming this could be called LEVEL_SEED. Anyway for an infinite world which you can reliably revisit areas without them changing, then you would need procedural generation for the area you are currently in, and given simplex noise is repeatable, then you can just change your function to iterate over the area you are currently in, and then map that area to the screen. i.e. you can iterate between

    screenCenterX - (screenWidth/2) to screenCenterX+ (screenWidth/2)
    

    with the inner iterator

    screenCenterY - (screenHeight/2) to screenCenterY+ (screenHeight/2)
    

    I guess there are many ways but simplex noise is not a random function i.e. a different result every time, which means it does kind of lend itself to a procedural generation approach. You might also want to look at this https://doc.mapeditor.org/en/stable/manual/using-infinite-maps/ which is a tile editor that allows dynamically super size map which is also pluggable into libGDX by which I mean its part of the libGDX framework. You can alway ask on the Discord chat group here https://libgdx.com/community/ because I can imagine you'd get a quick answer as prob many opinions.