From db3d5a86edda5b882213e6d4ac6b206800c9f3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vanicat?= Date: Mon, 2 Oct 2023 20:18:15 +0200 Subject: [PATCH 1/2] Flip texture also for animation Move the code that flip texture for fixed sprite to a function. Apply this fuction on animated texture. Fix #1916 --- arcade/tilemap/tilemap.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/arcade/tilemap/tilemap.py b/arcade/tilemap/tilemap.py index ffd06c088..4189a4463 100644 --- a/arcade/tilemap/tilemap.py +++ b/arcade/tilemap/tilemap.py @@ -102,6 +102,16 @@ def _get_image_source( return None +def _may_be_flip(tile, texture): + if tile.flipped_diagonally: + texture = texture.flip_diagonally() + if tile.flipped_horizontally: + texture = texture.flip_horizontally() + if tile.flipped_vertically: + texture = texture.flip_vertically() + return texture + + class TileMap: """ Class that represents a fully parsed and loaded map from Tiled. @@ -466,12 +476,7 @@ def _create_sprite_from_tile( height=height, hit_box_algorithm=hit_box_algorithm, ) - if tile.flipped_diagonally: - texture = texture.flip_diagonally() - if tile.flipped_horizontally: - texture = texture.flip_horizontally() - if tile.flipped_vertically: - texture = texture.flip_vertically() + texture = _may_be_flip(tile, texture) args = { "path_or_texture": texture, # type: ignore @@ -625,6 +630,8 @@ def _create_sprite_from_tile( f"tile '{frame_tile.id}', '{image_file}'." ) + texture = _may_be_flip(tile, texture) + key_frame = AnimationKeyframe( # type: ignore frame.tile_id, frame.duration, texture ) From 3d1f4857ef1c2710523ac35c4972ce5f857e61ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vanicat?= Date: Mon, 2 Oct 2023 23:52:19 +0200 Subject: [PATCH 2/2] Add type information on _may_be_flip --- arcade/tilemap/tilemap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/tilemap/tilemap.py b/arcade/tilemap/tilemap.py index 4189a4463..cea54b681 100644 --- a/arcade/tilemap/tilemap.py +++ b/arcade/tilemap/tilemap.py @@ -31,7 +31,7 @@ from arcade.texture.loading import _load_tilemap_texture if TYPE_CHECKING: - from arcade import TextureAtlas + from arcade import TextureAtlas, Texture from pyglet.math import Vec2 @@ -102,7 +102,7 @@ def _get_image_source( return None -def _may_be_flip(tile, texture): +def _may_be_flip(tile: pytiled_parser.Tile, texture: Texture) -> Texture: if tile.flipped_diagonally: texture = texture.flip_diagonally() if tile.flipped_horizontally: