creating and writing data into tmx

Hello everyone
This is my 1st post, excuse me if my formatting is bad :slight_smile:

I have been trying to make a tile based level editor for my game.
I managed to create the level and tools needed to edit the level and change tiles using that.
But after i edited the level i want to save it in .tmx format file.
Problem is i couldn’t find a way to do it. I understood that this steps are taken for generating the data element in tmx file.
# encrypt the data using zlib or gzip
# convert the encrypted data into base 64 string.

I have trouble with understanding the format in which data is supposed to be.

should it be like numbers separated by comma 1,3,2,2,2,2,2,4,1,6………
or separated by space 1 3 2 2 2 2 2 4 1 6……… or what ever format it is supposed to be.

I tried to look at format by putting break points in CCTMXXMLParser.
But all i can see is that the data is in array of unsigned char which is contains all the numbers.
this unsigned char buffer is inflated using ccInflateMemoryWithHint(i have no idea what this inflate function is about :frowning: ) and the resultant inflated buffer is type casted to unsigned int.

can anyone tell me the format of the data that need to be encrypted and base 64

bump :frowning:
anyone help??

For those who have the same problem i figured it out.
The way i’m thinking is wrong.
Lot of java ruined my thinking about basic byte level operations.
The data is binary data (byte data). The array of integers that represent the tile ids are converted into bytes and then these bytes are converted into base 64 then compressed.

Here is a sample code on how this can be done

// map tile data
unsigned tileData[5] = {4, 4, 4, 4, 4};

// the array is being casted to void pointer and this is in turn is casted to 
// char pointer the final result will contain the byte data
char *byteData = static_cast(static_cast(&tileData));

// encoded this byteData into base 64
std::string encoded = base64_encode(reinterpret_cast(&byteData[0]), sizeof( tileData ));

// output the encoded data
std::cout << "base 64 encoded: " << encoded << std::endl;

i used base 64 encoding function from this link

http://www.adp-gmbh.ch/cpp/common/base64.html

you can find compression algorithm from net and use it to compress the encoded and write it into file