Infinite Area

Hi, I’m making a game where you can go on a 2D grid forever and it will always have randomized items placed on the grid. I was wondering how I could do this. I will appreciate any help.

The general idea is to keep in the scene only the part of the grid which is visible at the moment, plus say one extra screen in any direction.

Then, every frame, you check the location of the camera, compare it to it’s previous location, and if it moved to a new grid tile, then you destroy the part of the grid that is now outside the range defined, and instantiate the new line that is now within the range. When instantiating a new line, you can generate objects on it in random.

One thing you need to keep in mind - if you want the game to remember the areas that have already been (so if a player goes back to previous area he will have the same items), you will need to store it in memory, or if it gets too big, in disk.