-
Notifications
You must be signed in to change notification settings - Fork 194
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
Fixed incorrect math for isometric screen-to-map tile projection. #239
base: master
Are you sure you want to change the base?
Conversation
There also seems to be an incorrect check for out-of-bounds in the method Note that when the camera is moved, everything is fine. However, when the tilemap is moved, the method now returns The problem seems to be here:
If I'm not overlooking something, the pixel coordinates must always be relative to the tilemap layer itself, so considering
|
…nstead of treating the tilemap as orthogonal, filling a rectangular area completely; however, possibly due to floating point rounding errors, a few pixels at the bottom right of the map will pass the in-bounds test and "wrap" around when passed on to the screenToChart method
On second look, the method above to check for out-of-bounds is still insufficient. The tilemap is basically treated as orthogonal, filling its rectangular area completely: The correct way to check appears to be this:
The map is now treated as isometric and the empty corners return as out-of-bounds: However, possibly due to floating point rounding errors, there's a few stray pixels at the bottom-right that pass the check when they probably shouldn't, causing the I'm really not sure about the best way to fix that. |
@Sam-Izdat Great work! Definitely looking forward to looking at this and merging it into the next commit. |
Thanks - happy to be of use. I think grunt is misbehaving on windows, though, so I may have to fix that last commit when I have access to my linux box. The reasoning for the last edit was: multiplying is somewhat faster than dividing and caching should shave off a few cycles. It's probably bordering on micro-optimization, but I figured it'd be best, since this will run in the update loop more often than not. |
I've just discovered that we haven't addressed this PR, since @BenjaminHarding moved on to other projects. It looks good and I intend to fully review and merge it at some point in the future. Full disclosure: we're short-handed and super busy with other priorities, so KiwiJS hasn't had the love it needs in a little while. KiwiJS is a key part of those other projects, so we'll get this done sooner or later. It's just taking longer than I like. I'll probably use git trickery to merge the branch onto v1.5.0, the current working branch, for review. I think that will mean closing this request, so don't be surprised when that happens. I'm keeping it open for now as a reminder, and will of course credit everything in the release. |
The isometric projection math for
screenToChart
was a little screwy, causing some undesired behavior:I changed this math to correspond to the expected behavior, same as in the Tiled Map Editor: