I am working on a game that requires a tile map saved in multidimensional array. In my game I have all of these maps made that are NSStrings with all the saved values needed, I’m looking to save all the 256 values of the NSString into an int 16×16 multidimensional array.
Here is my current code however it doesn’t work
-(void)LoadMap:(NSString*)mapString
{
for(int h = 0; h < kMapSize; h++)
{
for(int w = 0; w < kMapSize; w++)
{
map[w][h] = [[mapString substringWithRange:NSMakeRange((h)+(w*kMapSize), 1)] intValue];
}
}
}
Any help would be great thankyou 🙂
There are two potential errors:
kMapSizeis possibly not equal to 16. This variable has a misleading name since the casual reader would think it should be 256. Perhaps rename itkMapWidth.mapStringis possibly not 256 characters long. You might want to check[mapString length]at the beginning ofLoadMap.