I've tried googling for a solution, but I haven't been successful. For a loooong looong time I have been using this format for loading a tile map:
Code: Select all
0 0 0 0 0 0 0
0 0 1 1 2 0 0
0 0 1 1 2 0 0
Here are the loading and map rendering functions:
Rendering Function
Code: Select all
void Level::RenderMap()
{
for(int x=0; x<mapW*2; x++)
{
for(int y=0; y<mapH*2; y++)
{
for(int z=0; z<10; z++)
{
if(tileArray[y][x] == z)
{
tiles->DrawSubImage(x*tileW - camera.x, y*tileH - camera.y, 32, 32, screen, z, 0);
}
}
}
}
}
Code: Select all
bool Level::LoadTiles()
{
mapfile.open(leveldir, ios::in);
if(!mapfile.is_open() )
{
cout << "Could not load " << leveldir <<"."<<endl;
return false;
}
for( int x=0; x < mapW; x++ )
{
for(int y=0; y<mapH; y++)
{
mapfile >> tileArray[x][y];
}
}
mapfile.close();
return true;
}