coordForPoint not working for isometric maps
I try to find out the tile coordinate for a world coordinate. I tried to used the coordForPoint-function but it doesn't work correctly for my isometric map. Is there a way to calculate the tile coordinate for a world coordinate on isometric maps ?
I'm not sure exactly what you are asking here. Are you wanting something more than the (translated to world) coordinates of a given sprite?
I would like to know the tile coordinate for the current touch. I thought coorForPoint can be used to calculate it but it returns the wrong coordinates for my isometric map. Can this function be used for that or is there another way to calculate the tile for a touch ? I also tried to use tileAt(which uses the coorForPoint-function), it also returns sprites far away from the touch coordinate.
Thanks in advance. Btw : Thanks for publishing this class, it is great!
@Nightmare82 are you scaling the map at all? If you are then you may need to factor the scaling into the touch point as well to get the appropriate response.
No I don't scale the map. Should the method coorForPoint return the correct tile-coordinates for isometric maps too ? The sprite is positioned with this code:
sprite.position = CGPointMake((layer.mapTileSize.width / 2.0) * (layerInfo.layerGridSize.width + col - row - 1), (layer.mapTileSize.height / 2.0) * ((layerInfo.layerGridSize.height * 2 - col - row) - 2) );
And coordForPoint uses the same calculation for all maps:
- (CGPoint) coordForPoint:(CGPoint) inPoint
{
// invert y axis
inPoint.y = [self layerHeight] - inPoint.y;
int x = inPoint.x / _mapTileSize.height;
int y = (int)inPoint.y / _mapTileSize.width;
return CGPointMake(x, y);
}
Shouldn't the calculation be different for isometric maps ?
@Nightmare82 you are correct, this does not work properly and needs to be rewritten in the case of isometric maps to do the right thing. I am not an iso map expert by any means, so help would be appreciated.
OK thanks for your answer. I currently work on another task but if I find a solution I'll let you know.