Hi,
I need an exact collision detection and I tried something thats too heavy for the touch 2g :P.
I draw objects as bounding boxes around the obstacles with Tiled and as name I use "Obstacle".
So in my implemetation I make an array of CGRect's wich I get from the tmx.
obstacles = [[NSMutableArray alloc] init];
for (NSDictionary *dict in [objects objects]) {
if ([[dict valueForKey:@"name"] isEqualToString:@"Obstacle"]) {
CGRect rect = CGRectMake([[dict valueForKey:@"x"] intValue],
[[dict valueForKey:@"y"] intValue],
[[dict valueForKey:@"width"] intValue],
[[dict valueForKey:@"height"] intValue]);
[obstacles addObject:[NSValue valueWithCGRect:rect]];
}
}
And every frame I check if the CGRect of the player intersect one of the obstacles.
In code:
CGRect playerRect = CGRectMake(player.position.x-playerWidth/2, player.position.y-playerHeight/2, playerWidth, playerHeight);
for (NSValue *rect in obstacles) {
if (CGRectIntersectsRect([rect CGRectValue], playerRect)) {
collided = YES;
}
}
Some hints?