arcade icon indicating copy to clipboard operation
arcade copied to clipboard

center_x and center_y do not update when changing a Sprite's texture to one of a different size

Open DigiDuncan opened this issue 3 years ago • 6 comments

Bug Report

Actual behavior:

See title.

Expected behavior:

The center_x and center_y should reflect the new positioning due to its texture changing.

Steps to reproduce/example code:

  1. Create a Sprite with a Texture.
  2. Check it's center_x and center_y.
  3. Update its Texture to one of a different size.
  4. Observe no change to the Sprite's center_x and center_y properties.
b = sprite.bottom
sprite.set_texture(1)  # different size
sprite.bottom = b  # does nothing, even though the size is different

Screenshot.

DigiDuncan avatar Feb 21 '22 20:02 DigiDuncan

What there anything related to collision what prevented us from updatding this? I know several people have commented on this issue before, but I don't really know the implications of doing this change.

einarf avatar Feb 21 '22 21:02 einarf

We didn't update the hitbox because changing a texture could cause the hitbox to update such that the sprite would now be colliding with a wall. The physics engine at the time was terrible, and if it suddenly found a player in a wall it would teleport her any-which-way to get her out. Now the engine is only slightly less primitive, and it more likely to 'guess' a better collision resolution, but it still isn't great.

pvcraven avatar Feb 21 '22 22:02 pvcraven

Would it be possible to have a update_hitbox() I could call after changing the texture, such that I could then set .bottom and it actually reflect the new size of the Texture? I'm struggling to get it to work like I'd like in pure code without that and my game doesn't use collision detection.

DigiDuncan avatar Feb 22 '22 23:02 DigiDuncan

You can update the hitbox yourself:

my_sprite.hit_box = my_texture.hit_box_points

pvcraven avatar Feb 23 '22 00:02 pvcraven

I'm thinking this will not change, other than the doc updates. At some point in the future we might support adding a baseline, or whatever it is like Unity does, where we change the center.

pvcraven avatar Mar 21 '22 16:03 pvcraven

At the very least we should offer some method to re-center the sprite just like we have for syncing the hit box with the current texture. Moved to 3.x.x so it doesn't disappear in the void.

einarf avatar Feb 18 '24 03:02 einarf