Skip to content

Fix AnimatedWalkingSprite.update_animation clobbering scale_y - #2876

Open
uttam12331 wants to merge 1 commit into
pythonarcade:developmentfrom
uttam12331:fix-animatedwalkingsprite-scale-y
Open

Fix AnimatedWalkingSprite.update_animation clobbering scale_y#2876
uttam12331 wants to merge 1 commit into
pythonarcade:developmentfrom
uttam12331:fix-animatedwalkingsprite-scale-y

Conversation

@uttam12331

Copy link
Copy Markdown

Summary

AnimatedWalkingSprite.update_animation sizes the sprite from the texture, but the height line uses scale_x instead of scale_y:

self.width  = self._texture.width  * self.scale_x
self.height = self._texture.height * self.scale_x   # should be scale_y

The inherited height setter derives scale_y from the value assigned (self._scale = self._scale[0], value / self._texture.height), so assigning texture.height * scale_x forces scale_y := scale_x. Every animation update therefore both mis-sizes the sprite and silently corrupts a non-uniform scale.

Repro (arcade 3.3.3):

tex = arcade.Texture.create_empty("t", (10, 20))
spr = arcade.AnimatedWalkingSprite(scale=(2.0, 3.0))
spr.stand_right_textures = [tex]; spr.texture = tex
spr.change_x = spr.change_y = 0
spr.update_animation()
# before: spr.scale == (2.0, 2.0), spr.height == 40.0   <- scale_y clobbered 3.0 -> 2.0
# after:  spr.scale == (2.0, 3.0), spr.height == 60.0

Fix

Use scale_y for the height. The width line one above already correctly uses scale_x, matching the base-class texture setters (sprite/base.py, sprite/sprite.py) which use _scale[0] for width and _scale[1] for height.

self.height = self._texture.height * self.scale_y

Test

Added test_update_animation_preserves_scale_y in tests/unit/sprite/test_sprite_animated_walking.py — it constructs an AnimatedWalkingSprite(scale=(2.0, 3.0)), runs update_animation, and asserts the scale and dimensions are preserved. It fails on development (scale becomes (2.0, 2.0), height 40.0) and passes with this change. ruff format --check clean and the change adds no new ruff check findings.

AnimatedWalkingSprite is soft-deprecated in its docstring, but it is still exported in arcade.__all__ and is the sprite used in the platformer tutorial (platformer_part_twelve), so the silent scale corruption still affects users following the docs.

update_animation set height from scale_x instead of scale_y:
    self.height = self._texture.height * self.scale_x
The height setter derives scale_y from the assigned value, so this
forced scale_y := scale_x on every animation update -- mis-sizing the
sprite and silently corrupting a non-uniform scale (e.g. scale (2, 3)
became (2, 2)). The width line one above already uses scale_x, matching
the base-class setters which use _scale[0] for width and _scale[1] for
height. Use scale_y.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant