How to do "map chunks", like terraria or minecraft maps?

Posted by O'poil on Stack Overflow See other posts from Stack Overflow or by O'poil
Published on 2012-03-18T13:02:06Z Indexed on 2012/03/18 18:02 UTC
Read the original article Hit count: 213

Filed under:
|
|

Due to performance issues, I have to cut my maps into chunks. I manage the maps in this way:

listMap[x][y] = new Tile (x,y);

I tried in vain to cut this list for several "chunk" to avoid loading all the map because the fps are not very high with large map. And yet, when I update or Draw I do it with a little tile range. Here is how I proceed:

foreach (List<Tile> list in listMap)
{
    foreach (Tile leTile in list)
    {
        if ((leTile.Position.X < screenWidth + hero.Pos.X) &&
            (leTile.Position.X > hero.Pos.X - tileSize) &&
            (leTile.Position.Y < screenHeight + hero.Pos.Y) &&
            (leTile.Position.Y > hero.Pos.Y - tileSize)
        )
        {
            leTile.Draw(spriteBatch, gameTime);        
        }
    }
}

(and the same thing, for the update method).

So I try to learn with games like minecraft or terraria, and any two manages maps much larger than mine, without the slightest drop of fps. And apparently, they load "chunks".

What I would like to understand is how to cut my list in Chunk, and how to display depending on the position of my character. I try many things without success.

Thank you in advance for putting me on the right track!

Ps : Again, sorry for my English :'( Pps : I'm not an experimented developer ;)

© Stack Overflow or respective owner

Related posts about c#

Related posts about algorithm