• Advertisement
Sign in to follow this  

interpriting tiles

This topic is 4922 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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[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
oo so if im reading this right the switch is thrown every time you read your array and then the case statements take over ok i think i get it (if thats whats happening) tanks both of you!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement