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

Hex coord conversion fix (and also EmmyLua comments) #262

Closed
wants to merge 2 commits into from
Closed

Hex coord conversion fix (and also EmmyLua comments) #262

wants to merge 2 commits into from

Conversation

chadvandy
Copy link

@chadvandy chadvandy commented Dec 22, 2021

Got a fix here to resolve the standing issues with converting tiles to pixels and vice versa. I similarly pulled the math from Tiled's source, but made a few changes that seem to fix the issues. Notably, Tiled uses (0,0) as the origin, while STI assumed it was (1,1). The two functions - convertPixelToTile and vice versa - treat origin like (0,0), but I haven't adjusted that for the other grid types. You can either just adjust the math by +1 for my code, or adjust the origin to (0,0), doesn't matter.

Tested this quite a bit, seems to work fine. I didn't get a chance to confirm it with an isometric staggered tile set, may want to do that.

I also included EmmyLua comments, in a separate commit. I wrote those for my own sake but feel free to merge them in, it helped me pick up the API quicker.

#113 <- fix for this

I wrote this based off of the Tiled source code, as the original code was; didn't realize your code had already been based off of it, which is why mine looks different. I think it was just a couple minor things transitioning from C++ to Lua here, the distance-squared function and the offsets were a little off.

Tested these functions extensively, they seem to work 100% fine.
@chadvandy chadvandy closed this by deleting the head repository Jul 1, 2023
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

Successfully merging this pull request may close these issues.

1 participant