Jump to content
  • Advertisement

Archived

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

Laroche

Tile identifiers

This topic is 6021 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 Tilemap

fwrite(&Height,sizeof(int),1,TileFileOut); // so, later you know whats the Height of the Tilemap

fwrite(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 Map

fread(&Height,sizeof(int),1,TileFileIn); // Get Height of the Map

TileArray = new int[Width*Height]; // allocate memory for the map

freaf(TileArray,sizeof(int),(Width*Height),TileFileIn);
fclose(TileFileIn);




Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!