Hey guys, I have a tmx tilemap loaded into my project with a layer specifically for collisions that detects collisions fine!
My problem is a simple one (in theory), so forgive me if im missing an obvious solution. I cant figure out how to get my sprite to stop moving when it detects one of these tiles! My code is as follows
-(void) update:(ccTime)delta
{
int pos1X = floor(tank.position.x / tileMap.tileSize.width);
int pos1Y = floor(tileMap.mapSize.height - (tank.position.y / tileMap.tileSize.height));
collisionLayer = [tileMap layerNamed:@"Collision"];
unsigned int gid1 = [collisionLayer tileGIDAt:ccp(pos1X, pos1Y)];
if (gid1 ==11) {
[self stopAllActions];
NSLog(@"COLLISION!");
}
}
as you can see i added an NSLog statement to tell me when my player is on a tile, the map follows the sprite using CCFollow, so the sprite stays in the moddle and it is controlled using a joystick.
PLEASE HELP.
thanks in advance