Skip to content

Commit 6498500

Browse files
committed
Declare draw_range on SpriteSequence
1 parent 55b4543 commit 6498500

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

‎arcade/sprite_list/sprite_list.py‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,35 @@ def draw(
132132
"""
133133
...
134134

135+
@abstractmethod
136+
def draw_range(
137+
self,
138+
start: int = 0,
139+
stop: int | None = None,
140+
*,
141+
filter: PyGLenum | OpenGlFilter | None = None,
142+
pixelated: bool | None = None,
143+
blend_function: BlendFunction | None = None,
144+
) -> None:
145+
"""Draw the sprites selected by ``sprite_list[start:stop]``.
146+
147+
The bounds follow Python slicing: ``stop`` is exclusive, negative
148+
indices count from the end, and out-of-range bounds are clipped.
149+
The sprites keep their list order, without creating a temporary list.
150+
151+
Args:
152+
start: Index of the first sprite to draw.
153+
stop: Exclusive end index. ``None`` draws to the end of the list.
154+
filter: Optional OpenGL texture filter, as in :meth:`draw`.
155+
pixelated: Whether to use pixelated rendering, as in :meth:`draw`.
156+
blend_function: Optional OpenGL blend function, as in :meth:`draw`.
157+
158+
Raises:
159+
ValueError: A custom texture-storage shader does not support the
160+
``sprite_start`` uniform required for a nonzero start index.
161+
"""
162+
...
163+
135164
@abstractmethod
136165
def draw_hit_boxes(
137166
self, color: RGBOrA255 = (0, 0, 0, 255), line_thickness: float = 1.0
@@ -1081,23 +1110,6 @@ def draw_range(
10811110
pixelated: bool | None = None,
10821111
blend_function: BlendFunction | None = None,
10831112
) -> None:
1084-
"""Draw the sprites selected by ``sprite_list[start:stop]``.
1085-
1086-
The bounds follow Python slicing: ``stop`` is exclusive, negative
1087-
indices count from the end, and out-of-range bounds are clipped.
1088-
The sprites keep their list order, without creating a temporary list.
1089-
1090-
Args:
1091-
start: Index of the first sprite to draw.
1092-
stop: Exclusive end index. ``None`` draws to the end of the list.
1093-
filter: Optional OpenGL texture filter, as in :meth:`draw`.
1094-
pixelated: Whether to use pixelated rendering, as in :meth:`draw`.
1095-
blend_function: Optional OpenGL blend function, as in :meth:`draw`.
1096-
1097-
Raises:
1098-
ValueError: A custom texture-storage shader does not support the
1099-
``sprite_start`` uniform required for a nonzero start index.
1100-
"""
11011113
start, stop, _ = slice(start, stop).indices(len(self.sprite_list))
11021114
if stop <= start or not self._visible or self.alpha_normalized == 0.0:
11031115
return

‎tests/unit/spritelist/test_spritelist_draw_range.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_render_control(offscreen, storage_backend):
4545
],
4646
)
4747
def test_slice_bounds(offscreen, storage_backend, start, stop, expected):
48-
sprites = make_sprites(lazy=True)
48+
sprites: arcade.SpriteSequence[arcade.Sprite] = make_sprites(lazy=True)
4949
sprites.draw_range(start, stop)
5050
for i, color in enumerate(COLORS):
5151
assert offscreen.read_pixel(10 + 10 * i, 10) == (color[:3] if i in expected else (0, 0, 0))

0 commit comments

Comments
 (0)