#### Archived

This topic is now archived and is closed to further replies.

# Tile identifiers

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

## Recommended Posts

In every tutorial it says that all you do is give a tile a number, like 1 = grass, 2 = dirt, etc. This is then saved into a map file called "Whatever.Whatever" and looks like: 02030406020 87432689672 83409908835 24782935699 or whatever. This is ridiculous though. Does this mean we are limited to 10 tiles? (0-9) how does the computer know what number is a single digit number and how can it seperate it from the double or triple digit ones? how do you go around this? what will the map save-game look like? thanks (im using c++ with msvs6)

##### Share on other sites
Easy solution: Use 16 bit values for each tile, and store the number in binary, not ascii. You can now have about 65,000 different tiles.

##### Share on other sites
could you show me an example in a c++ struct please? im not sure to store the numbers in binary.

##### Share on other sites
you dont need a struct, just an array of numbers

int Width; // contains width of the map in tiles, or number of columns
int Height; // contains Height of the map in tiles, or number of rows

int *TileArray = new int[Width*Height];

and then you just access each tile with TileArray[(y*Width)+x] where x,y is the coordinate of the tile you want to access, when you want to save your information then:
  FILE *TileFileOut = fopen("yourfilename.bin","wb");fwrite(&Width,sizeof(int),1,TileFileOut); // so, later you know whats the Width of the Tilemapfwrite(&Height,sizeof(int),1,TileFileOut); // so, later you know whats the Height of the Tilemapfwrite(TileArray,sizeof(int),(Width*Height),TileFileOut);fclose(TileFileOut);

later when you want to load a saved map:
  FILE *TileFileIn = fopen("yourfilename.bin","rb");fread(&Width,sizeof(int),1,TileFileIn); // Get The Width of the Mapfread(&Height,sizeof(int),1,TileFileIn); // Get Height of the MapTileArray = new int[Width*Height]; // allocate memory for the mapfreaf(TileArray,sizeof(int),(Width*Height),TileFileIn);fclose(TileFileIn);

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633762
• Total Posts
3013726
×