Repository navigation
Rescale the hit box in rescale_relative_to_point() - #2899
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:update_spatial_hash()reads the hit box.SpriteList.rescale()callsrescale_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.scalebeforeself._scale, the same way the other scale setters do.Tests
test_rescale_relative_to_point_scales_hit_boxchecks:get_sprites_at_pointon a spatial-hashed list after rescaling down,test_sprite_list_rescale_scales_hit_boxeschecksSpriteList.rescale().developmentand pass with the fix. The existing rescale tests still pass.Changelog
Added entries for this fix and for the benchmark scripts from #2896, which didn't have one.
🤖 Generated with Claude Code