Skip to content

Changing Sprite.width/height does not update hitbox #752

@eruvanos

Description

@eruvanos

Bug Report

Changing Sprite.width/height does not update hitbox.

This results in wrong behaviour using:

  • Sprite.left/right/top/bottom
  • Sprite.collides_with_point
  • GUI Button clicks

Actual behavior:

Running example code fails with AssertionError

Expected behavior:

Changing properties of sprite like Sprite.width/height should update the hitbox.
Example code draws Sprite, passing the asserts

Steps to reproduce/example code:

import arcade
from arcade import Window, Sprite, get_window


class MyWindow(Window):
    def __init__(self):
        super().__init__()
        arcade.set_background_color((0, 0, 0))

        self.sprite = Sprite(":resources:images/space_shooter/playerShip1_orange.png")
        self.sprite.position = get_window().width / 2, get_window().height / 2,

        # Sprite width before : 90
        print(self.sprite.width)

        # Double sprite width: 180
        self.sprite.width = 180
        print(self.sprite.width)

        hit = self.sprite.collides_with_point((self.sprite.center_x + 80, self.sprite.center_y))
        assert hit
        assert self.sprite.right == self.sprite.center_x + 90

    def on_draw(self):
        arcade.start_render()
        self.sprite.draw()


if __name__ == '__main__':
    window = MyWindow()
    arcade.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions