Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coordForPoint not working for isometric maps #10

Open
Nightmare82 opened this issue Jun 29, 2014 · 6 comments
Open

coordForPoint not working for isometric maps #10

Nightmare82 opened this issue Jun 29, 2014 · 6 comments

Comments

@Nightmare82
Copy link

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 ?

@slycrel
Copy link
Owner

slycrel commented Jul 1, 2014

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?

@Nightmare82
Copy link
Author

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!

@slycrel
Copy link
Owner

slycrel commented Jul 11, 2014

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

@Nightmare82
Copy link
Author

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 ?

@slycrel
Copy link
Owner

slycrel commented Aug 3, 2014

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

@Nightmare82
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants