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

screenToTileCoords Calculation Issue #9

Closed
technicallyerik opened this issue Apr 10, 2017 · 2 comments
Closed

screenToTileCoords Calculation Issue #9

technicallyerik opened this issue Apr 10, 2017 · 2 comments
Assignees
Labels

Comments

@technicallyerik
Copy link
Contributor

I have a flat-topped tilemap setup in Tiled as follows:

<map version="1.0" orientation="hexagonal" renderorder="right-down" width="16" height="16" tilewidth="75" tileheight="65" hexsidelength="40" staggeraxis="x" staggerindex="odd" nextobjectid="9">

I'm having an issue with 'coordinateForPoint' not returning the correct coordinates for me.

I narrowed it down to this method in 'screenToTileCoords':

            if (tilemap.staggerX == true) {
                s = tilemap.sideLengthX
                r = (tileWidth - tilemap.sideLengthX) / 2
                h = tileHeight / 2
                
                pixelX -= r
                sectionX = pixelX / (r + s)
                sectionY = pixelY / (h * 2)
                
                // y-offset
                if tilemap.doStaggerX(Int(sectionX)){
                    sectionY -= 0.5
                }

Specifically: pixelX -= r. This causes pixels in the left-side tip of a flat-topped hex tile to be calculated to the previous X column. Removing this line causes pixels in the right-side tip of a flat-topped hex tile to be calculated to the next X column.

Barring any significantly more complicated calculations to figure out the column of an angled side, I split the difference with pixelX -= (r / 2) and it seems to be working 'good enough' for me. I'd appreciate your thoughts!

@mfessenden mfessenden self-assigned this Apr 17, 2017
@mfessenden mfessenden added the bug label Apr 17, 2017
@mfessenden
Copy link
Owner

Thanks for bringing this to my attention! I'm currently reviewing the coordinate conversion math for before my next update - there are a few issues around this.

@mfessenden
Copy link
Owner

This has been corrected with the 1.15 release so I'm going to close this. If anything is still not working for you, feel free to open a new issue.

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

No branches or pull requests

2 participants