Skip to content

Rescale the hit box in rescale_relative_to_point() - #2899

Merged
pvcraven merged 1 commit into
developmentfrom
fix/rescale-hit-box
Oct 1, 2026
Merged

pvcraven merged 1 commit into
developmentfrom
fix/rescale-hit-box

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 1, 2026

Copy link
Copy Markdown
Member

Problem

BasicSprite.rescale_relative_to_point() updated the sprite's scale, width and height, but not its hit box's scale, unlike every other scale setter (scale, scale_x, width, size, add_scale, ...). So after rescaling, the sprite was drawn at its new size but:

  • collided at its old size, and
  • was placed in spatial hashes at its old size, because update_spatial_hash() reads the hit box.
sprite = arcade.SpriteSolidColor(32, 32)
sprite.rescale_relative_to_point(sprite.position, 2)
sprite.scale          # (2.0, 2.0)
sprite.hit_box.scale  # development: (1.0, 1.0), this PR: (2.0, 2.0)

SpriteList.rescale() calls rescale_relative_to_point() for each sprite, so it had the same problem.

I found this while working on #2897. That PR didn't change this behavior, because both collision stages there use the hit box.

Fix

One line: set self._hit_box.scale before self._scale, the same way the other scale setters do.

Tests

  • test_rescale_relative_to_point_scales_hit_box checks:
    • the hit box scale and bounds after a non-uniform rescale,
    • a collision that only touches the rescaled size,
    • get_sprites_at_point on a spatial-hashed list after rescaling down,
    • rescaling relative to another point (the sprite moves and scales).
  • test_sprite_list_rescale_scales_hit_boxes checks SpriteList.rescale().
  • Both fail on development and pass with the fix. The existing rescale tests still pass.
  • Full unit suite: 1103 passed. The 3 failures are the render tests that only fail on my machine and pass in CI.

Changelog

Added entries for this fix and for the benchmark scripts from #2896, which didn't have one.

🤖 Generated with Claude Code

rescale_relative_to_point() updated the sprite's scale and size but not
its hit box's scale, unlike every other scale setter. The sprite was
drawn at its new size but collided, and was placed in spatial hashes, at
its old size. SpriteList.rescale() calls it, so it had the same problem.

Add tests for both, and changelog entries for this fix and for the
benchmark scripts added in #2896.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pvcraven
pvcraven merged commit a3a9eb2 into development Oct 1, 2026
7 checks passed
@pvcraven
pvcraven deleted the fix/rescale-hit-box branch October 1, 2026 14:51
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