So I'm making a side-scrolling adventure type game in Java. The worlds are procedurally generated, so I can't manually place tiles. Therefore, I every 20 ticks (1/3 second) I update every block's tile on the screen. I know this is a terrible solution, and it's causing a bit of lag. I tried only updating the blocks' tiles once when it was created, but it doesn't work well with the way I've programmed my world generation.
Basically, how the ground is generated is the top layer of ground is generated first, then when the player gets close enough, the layers below are created.
public void testForBlocks()
{
topTaken=false;
bottomTaken=false;
rightTaken=false;
leftTaken=false;
for(int i=0;i<handler.screenBlocks.size();i++)
{
Block b = handler.screenBlocks.get(i);
if(b.solid)
{
if(b.oneWay==oneWay)
{
if(b.x==x&&b.y==y+32)
bottomTaken=true;
if(b.x==x&&b.y==y-32)
topTaken=true;
if(b.y==y&&b.x==x+32)
rightTaken=true;
if(b.y==y&&b.x==x-32)
leftTaken=true;
}
}
}
setSprite();
}
This means that if I only update the tile's position once, the tile won't recognize that there is a block below it yet(because there isn't), and will be assigned the wrong tile.
Basically, my question is: How can I update tiles, while keeping it efficient?
I feel like I'm missing an obvious solution. Can anyone help me? Thanks in advance. :)
updating
tiles and why it's really inefficient. P.S. This resource could be useful: www-cs-students.stanford.edu/~amitp/gameprog.html#tiles \$\endgroup\$