Skip to content

Correct coordinate calculation for rectangle #1741

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

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions arcade/tilemap/tilemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,14 @@ def _process_object_layer(

shape = [x + offset[0], y + offset[1]]
else:
x = cur_object.coordinates.x + offset[0]
y = cur_object.coordinates.y + offset[1]
sx = x
sy = -y
ex = x + cur_object.size.width
ey = -(y + cur_object.size.height)
sx = cur_object.coordinates.x * scaling + offset[0]
sy = (
self.tiled_map.map_size.height * self.tiled_map.tile_size[1]
- cur_object.coordinates.y
) * scaling + offset[1]

ex = sx + cur_object.size.width * scaling
ey = sy - cur_object.size.height * scaling

p1 = [sx, sy]
p2 = [ex, sy]
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/tilemap/test_tilemap_objects.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from math import isclose
import arcade
from pytiled_parser.common_types import Color

Expand Down Expand Up @@ -34,6 +35,12 @@ def test_one():
assert sprite_1.properties["class"] == "crate"
assert sprite_1.properties["name"] == "crate1"

assert "Shapes" in tile_map.object_lists
rectangle = tile_map.object_lists["Shapes"][0]
assert isclose(rectangle.shape[2][0] - rectangle.shape[0][0], 573.60, abs_tol=0.02)
assert isclose(rectangle.shape[0][1] - rectangle.shape[2][1], 469.04, abs_tol=0.02)
assert isclose(tile_map.tiled_map.map_size.height * tile_map.tiled_map.tile_size[1] - rectangle.shape[0][1], 630.37, abs_tol=0.02)

# #
# # Test getting layer in group
# #
Expand Down