Skip to content

Commit 7eef141

Browse files
authored
Support drawing hitboxes using RBG or RGBA (#2628)
* Support drawing hitboxes using RBG or RGBA * Fix import order
1 parent fe2f203 commit 7eef141

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

arcade/scene.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from arcade import Sprite, SpriteList
1717
from arcade.gl.types import BlendFunction, OpenGlFilter
1818
from arcade.tilemap import TileMap
19-
from arcade.types import RGBA255, Color
19+
from arcade.types import Color, RGBOrA255
2020

2121
__all__ = ["Scene", "SceneKeyError"]
2222

@@ -499,7 +499,7 @@ def draw(
499499

500500
def draw_hit_boxes(
501501
self,
502-
color: RGBA255 = Color(0, 0, 0, 255),
502+
color: RGBOrA255 = Color(0, 0, 0, 255),
503503
line_thickness: float = 1.0,
504504
names: Iterable[str] | None = None,
505505
) -> None:

arcade/sprite/base.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from arcade.exceptions import ReplacementWarning, warning
88
from arcade.hitbox import HitBox
99
from arcade.texture import Texture
10-
from arcade.types import LRBT, RGBA255, AsFloat, Color, Point, Point2, Point2List, Rect, RGBOrA255
10+
from arcade.types import LRBT, AsFloat, Color, Point, Point2, Point2List, Rect, RGBOrA255
1111
from arcade.utils import copy_dunders_unimplemented
1212

1313
if TYPE_CHECKING:
@@ -764,7 +764,7 @@ def remove_from_sprite_lists(self) -> None:
764764

765765
# ----- Drawing Methods -----
766766

767-
def draw_hit_box(self, color: RGBA255 = BLACK, line_thickness: float = 2.0) -> None:
767+
def draw_hit_box(self, color: RGBOrA255 = BLACK, line_thickness: float = 2.0) -> None:
768768
"""
769769
Draw a sprite's hit-box. This is useful for debugging.
770770
@@ -774,10 +774,11 @@ def draw_hit_box(self, color: RGBA255 = BLACK, line_thickness: float = 2.0) -> N
774774
line_thickness:
775775
How thick the box should be
776776
"""
777+
converted_color = Color.from_iterable(color)
777778
points: Point2List = self.hit_box.get_adjusted_points()
778779
# NOTE: This is a COPY operation. We don't want to modify the points.
779780
points = tuple(points) + tuple(points[:-1])
780-
arcade.draw_line_strip(points, color=color, line_width=line_thickness)
781+
arcade.draw_line_strip(points, color=converted_color, line_width=line_thickness)
781782

782783
# ---- Shortcut Methods ----
783784

0 commit comments

Comments
 (0)