Skip to content

Commit b10bdd6

Browse files
authored
Fix sprite scaling issues (#1417)
1 parent c47f386 commit b10bdd6

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

arcade/sprite.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,7 @@ def width(self, new_value: float):
555555
if new_value != self._width:
556556
self.clear_spatial_hashes()
557557
self._point_list_cache = None
558-
559-
# If there is a hit box, rescale it to the new width
560-
if self._points:
561-
scale = new_value / self._width
562-
old_points = self._points
563-
self._points = [(point[0] * scale, point[1]) for point in old_points]
564-
558+
self._scale = new_value / self.texture.width, self._scale[1]
565559
self._width = new_value
566560
self.add_spatial_hashes()
567561

@@ -579,13 +573,7 @@ def height(self, new_value: float):
579573
if new_value != self._height:
580574
self.clear_spatial_hashes()
581575
self._point_list_cache = None
582-
583-
# If there is a hit box, rescale it to the new width
584-
if self._points:
585-
scale = new_value / self._height
586-
old_points = self._points
587-
self._points = [(point[0], point[1] * scale) for point in old_points]
588-
576+
self._scale = self._scale[0], new_value / self.texture.height
589577
self._height = new_value
590578
self.add_spatial_hashes()
591579

@@ -612,7 +600,7 @@ def scale(self, new_value: float):
612600
self._scale = new_value, new_value
613601
if self._texture:
614602
self._width = self._texture.width * self._scale[0]
615-
self._height = self._texture.height * self._scale[0]
603+
self._height = self._texture.height * self._scale[1]
616604

617605
self.add_spatial_hashes()
618606

@@ -1066,7 +1054,7 @@ def draw(self, *, filter=None, pixelated=None, blend_function=None) -> None:
10661054

10671055
self._sprite_list.draw(filter=filter, pixelated=pixelated, blend_function=blend_function)
10681056

1069-
def draw_hit_box(self, color: Color = BLACK, line_thickness: float = 1) -> None:
1057+
def draw_hit_box(self, color: Color = BLACK, line_thickness: float = 2.0) -> None:
10701058
"""
10711059
Draw a sprite's hit-box.
10721060

tests/unit2/test_sprite_collision.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_sprites_at_point():
3535

3636

3737
def test_sprite_collides_with_point():
38-
sprite = arcade.Sprite(center_x=0, center_y=0)
38+
sprite = arcade.SpriteSolidColor(32, 32, arcade.csscolor.RED)
3939
sprite.width = 2
4040
sprite.height = 2
4141

@@ -65,15 +65,15 @@ def test_sprite_collides_with_point():
6565

6666

6767
def test_sprite_collides_with_sprite():
68-
sprite_one = arcade.Sprite(center_x=0, center_y=0)
68+
sprite_one = arcade.SpriteSolidColor(32, 32, arcade.csscolor.RED)
6969
sprite_one.width = 10
7070
sprite_one.height = 10
7171

72-
sprite_two = arcade.Sprite(center_x=0, center_y=0)
72+
sprite_two = arcade.SpriteSolidColor(32, 32, arcade.csscolor.RED)
7373
sprite_two.width = 10
7474
sprite_two.height = 10
7575

76-
sprite_three = arcade.Sprite(center_x=0, center_y=0)
76+
sprite_three = arcade.SpriteSolidColor(32, 32, arcade.csscolor.RED)
7777
sprite_three.width = 1
7878
sprite_three.height = 1
7979

@@ -107,12 +107,14 @@ def test_sprite_collides_with_sprite():
107107
def test_sprite_collides_with_list():
108108
coins = arcade.SpriteList()
109109
for x in range(0, 50, 10):
110-
coin = arcade.Sprite(center_x=x, center_y=0)
110+
coin = arcade.SpriteSolidColor(32, 32, arcade.csscolor.RED)
111+
coin.position = x, 0
111112
coin.width = 10
112113
coin.height = 10
113114
coins.append(coin)
114115

115-
player = arcade.Sprite(center_x=100, center_y=100)
116+
player = arcade.SpriteSolidColor(32, 32, arcade.csscolor.RED)
117+
player.position = 100, 100
116118
player.width = 10
117119
player.height = 10
118120

0 commit comments

Comments
 (0)