Here's my code
-(NSMutableDictionary*)checkArrayForObject:(NSArray *)array withX:(int)mapX withY:(int)mapY withWith:(int)w withHeight:(int)h
{
NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc] init];
int cellWidth2 = w;
int cellHeight2 = h;
NSMutableArray *temp = [[NSMutableArray alloc ] initWithCapacity:(cellWidth2*cellHeight2)];
//lets fill the array with something
for (int iy=0; iy<cellWidth2; iy++) {
for (int ix=0; ix<cellHeight2; ix++) {
[temp addObject:[NSNull null]];
}
}
Boolean overObjectYES = YES;
Boolean overObjectNo = NO;
[tempDictionary setObject:[NSNumber numberWithBool:overObjectNo] forKey:@"collision"];
[tempDictionary setObject:temp forKey:@"regionArray"];
NSLog(@"mapx, %d", mapX);
NSLog(@"mapy, %d", mapY);
NSLog(@"cell width, %d", cellWidth2);
NSLog(@"cell height, %d", cellHeight2);
int xx = 0;
int yy = 0;
NSLog(@"DO CHECK");
for (int iy=mapY; iy<(mapY + cellHeight2); iy++) {
xx = 0;
for (int ix=mapX; ix<(mapX + cellWidth2); ix++) {
//make index
int ii = (iy*mapWidth)+ix;
NSLog(@"array index, %d", ii);
if([array objectAtIndex:ii] != [NSNull null])
{
NSLog(@"OVERLAPPING OBJECT");
[tempDictionary setObject:[NSNumber numberWithBool:overObjectYES] forKey:@"collision"];
//get object in real array
NSMutableDictionary *obj = [array objectAtIndex:ii];
//place in temp in same relative position
//make index
int ii2 = (yy*cellWidth2)+xx;
if(ii2 < [temp count])
{
[temp insertObject:obj atIndex:ii2];
}
}
xx++;
}
yy++;
}
return tempDictionary;
}
And in another method I call this method, but then I'm trying to get access to the object that has been stored in the array, but I can't seem to access it, or the above code (the insertObject:obj line) doesn't seem to insert anything.
This the code I'm using to access the above...
NSMutableDictionary *regionDictionary = [sharedInstance checkArrayForObject:sharedInstance.playerObjects withX:sharedInstance.mapTileX withY:sharedInstance.mapTileY withWith:1 withHeight:1];
Boolean overlap = [[regionDictionary objectForKey:@"collision"] boolValue];
if(overlap == YES)
{
[self setupInfoMsg:[[regionDictionary objectForKey:@"region"]objectAtIndex:0]];
}
When I step through that code and go into setupInfoMSg, the parameter = 0.
I'm new to Obj-c so it's probably a simple mistake.