Skip to content

Commit fe2f203

Browse files
authored
Make SpriteList.draw_hit_boxes ~20 times faster (#2627)
1 parent 47761fd commit fe2f203

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

arcade/sprite_list/sprite_list.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from arcade.gl.buffer import Buffer
2929
from arcade.gl.types import BlendFunction, OpenGlFilter, PyGLenum
3030
from arcade.gl.vertex_array import Geometry
31-
from arcade.types import RGBA255, Color, RGBANormalized, RGBOrA255, RGBOrANormalized
31+
from arcade.types import RGBA255, Color, Point2, RGBANormalized, RGBOrA255, RGBOrANormalized
3232
from arcade.utils import copy_dunders_unimplemented
3333

3434
if TYPE_CHECKING:
@@ -1114,10 +1114,22 @@ def draw_hit_boxes(
11141114
color: The color of the hit boxes
11151115
line_thickness: The thickness of the lines
11161116
"""
1117+
import arcade
1118+
11171119
converted_color = Color.from_iterable(color)
1120+
points: list[Point2] = []
11181121

1122+
# TODO: Make this faster in the future
1123+
# NOTE: This will be easier when/if we change to triangles
11191124
for sprite in self.sprite_list:
1120-
sprite.draw_hit_box(converted_color, line_thickness)
1125+
adjusted_points = sprite.hit_box.get_adjusted_points()
1126+
for i in range(len(adjusted_points) - 1):
1127+
points.append(adjusted_points[i])
1128+
points.append(adjusted_points[i + 1])
1129+
points.append(adjusted_points[-1])
1130+
points.append(adjusted_points[0])
1131+
1132+
arcade.draw_lines(points, color=converted_color, line_width=line_thickness)
11211133

11221134
def _normalize_index_buffer(self) -> None:
11231135
"""

0 commit comments

Comments
 (0)