Repository navigation
Fix StaggeredWorldToTileXY returning the wrong tile for most points - #7404
Open
vtxe02023274 wants to merge 1 commit into
Open
vtxe02023274 wants to merge 1 commit into
vtxe02023274 wants to merge 1 commit into
Conversation
It used the tile bounding boxes, which overlap between rows, and shifted odd rows the wrong way. It now finds the diamond the point is in. Fixes phaserjs#7144
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR
Describe the changes below:
Fixes #7144
getTileAtWorldXYon a staggered map returned the wrong tile for most points.StaggeredWorldToTileXYhad two problems:With
snapToFloorit now finds the diamond the point is in. In half tile units the diamond centers are whereu + vandu - vare both even, so it rounds to that grid and converts back to tile x and y. The non snapped result is left as it was, a fractional tile position does not have one clear meaning on a staggered grid.The tests for the snapped path checked the old results, for example (32, 32) is the center of tile (0, 1) but was expected to be (1, 2). They now check the center and the four corners of every tile in a few tile sizes, the corners of the bounding box, the odd row shift, and the layer offset, scale and scroll cases with tile centers.
Checked in Chrome as well: a 6x8 staggered Tiled JSON map with a different color for every tile, 3034 random points where the rendered pixel is a tile color, comparing that color to
layer.getTileAtWorldXY. Before this change 2295 of them were wrong, after it none are.npm run lintfails on master with ESLint 10 (.eslintrc.jsonneeds an import attribute), so I raneslint@8with.eslintrc.jsonon the changed file, no errors.