Hey!
Im just new with tiled.
Im creating a Tmx file using xcode directly.
All working great if I use pure xml on data tag :
NSMutableString *xml = [[NSMutableString alloc]init];
// header
[xml appendFormat:@"<map version=\"1.0\" orientation=\"orthogonal\" width=\"30\" height=\"30\" tilewidth=\"64\" tileheight=\"64\" >\n"];
// tilesets..
[xml appendFormat:@"<tileset firstgid=\"1\" name=\"Floor\" tilewidth=\"64\" tileheight=\"64\">\n"];
[xml appendFormat:@"<image source=\"Floor@2x.png\" width=\"64\" height=\"64\"/>\n"];
[xml appendFormat:@"</tileset>"];
// layers
[xml appendFormat:@"<layer name=\"Flo\" width=\"30\" height=\"30\">\n"];
[xml appendFormat:@"<data>\n"];
NSMutableString *Data;
NSString *GidTile;
for(int i=0;i<899;i++)
{
GidTile=[NSString stringWithFormat:@"1"];
[Data appendFormat:@"<tile gid=\"%@\">",GidTile];
}
[xml appendFormat:theString];
[xml appendFormat:@"</data>"];
[xml appendFormat:@"</layer>"];
[xml appendFormat:@"</map>"];
if I open the file created with Tiled all works as expected. It generates a tmx with the correct format. The problems comes when I want to use base64 to encode the data. Im using the following function to encode the “Data” NSstring on base64:
- (NSString *)base64String:(NSString *)str
{
NSData *theData = [str dataUsingEncoding: NSASCIIStringEncoding];
const uint8_t* input = (const uint8_t*)[theData bytes];
NSInteger length = [theData length];
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
uint8_t* output = (uint8_t*)data.mutableBytes;
NSInteger i;
for (i=0; i < length; i += 3) {
NSInteger value = 0;
NSInteger j;
for (j = i; j < (i + 3); j++) {
value <<= 8;
if (j < length) {
value |= (0xFF & input[j]);
}
}
NSInteger theIndex = (i / 3) * 4;
output[theIndex + 0] = table[(value >> 18) & 0x3F];
output[theIndex + 1] = table[(value >> 12) & 0x3F];
output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '=';
output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
}
return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
}
But its don’t give me the same base64 string that Tile does If I save the exact map using the application. I don’t really get it I would be very happy if someone can help with this!
Regards & thanks for your time!