//Position to tileCoord
-(CGPoint)tileCoordForPosition:(CGPoint) position 
{
    int x = position.x / tileMap.tileSize.width;
    int y = ((tileMap.mapSize.height * tileMap.tileSize.height) - position.y) / tileMap.tileSize.height;
    
    return ccp(x,y);
}

//tileCoord to Position
-(CGPoint)positionFromTileCoord:(CGPoint) tileCoord{
    
    int x=tileCoord.x * tileMap.tileSize.width + tileMap.tileSize.width/2;
    int y=tileMap.mapSize.height * tileMap.tileSize.height - tileCoord.y * tileMap.tileSize.height - tileMap.tileSize.width/2;
    
    return ccp(x, y);
}

相关文章: