Sign in to follow this  
raptorstrike

interpriting tiles

Recommended Posts

ok i know what needs to go into a tile map array[2][3]={{1,2} {0,2} {1,1}} and an array of tile pictures array_p[3] but how do you get from a bunch of numbers that represent tiles to acctualy bliting them on the screen how do you get your program to see those numbers as values representing tiles?? thanks

Share this post


Link to post
Share on other sites
Well, you almost have it. In fact, you should know what does your array_p contains. A bitmap? A tile instance?

here's some pseudo-code to write tiles, considering you have a Draw function that can draw a tile at the given position, and the tiles are 50*50 pixels


for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 3; j++)
{
Draw(50*i, 50*j, array_p[array[i][j]];
}
}



So, the hard part is to create that "Draw" function, and to load bitmaps in a way or another, to blit them on the screen.

Share this post


Link to post
Share on other sites
The numbers that go into the tile map are ID numbers of your internal tile store. So imagine you've got a few textured tiles loaded, 0 = ground 1 = grass 2 = wall, etc, your tile map would contain the correct number for the tile you need.

When rendering or performing any other actions on the tile, you'd throw in a switch statement to ensure you're performing the correct action for your specified tile.



// Stupid example in pseudo code
void rendertiles()
{
for (int row = 0; row < maxrows; row++)
{
for (int col = 0; col < maxcols; col++)
{
switch ( tile[row][col] )
{
case 0:
// Render ground tile
break;

case 1:
// Render grass tile
break;

case 2:
// Render wall tile
break;

// etc

}
}


}

}





Obviously that's a vastly simplified example, but it should show you what I mean.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this