JSTileMap icon indicating copy to clipboard operation
JSTileMap copied to clipboard

coordForPoint not working for isometric maps

Open Nightmare82 opened this issue 11 years ago • 6 comments

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 ?

Nightmare82 avatar Jun 29 '14 11:06 Nightmare82

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?

slycrel avatar Jul 01 '14 13:07 slycrel

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 avatar Jul 02 '14 08:07 Nightmare82

@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.

slycrel avatar Jul 11 '14 06:07 slycrel

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 avatar Jul 11 '14 07:07 Nightmare82

@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.

slycrel avatar Aug 03 '14 01:08 slycrel

OK thanks for your answer. I currently work on another task but if I find a solution I'll let you know.

Nightmare82 avatar Aug 15 '14 15:08 Nightmare82