Skip to content

Add SpriteList.draw_range for partial batch rendering - #2980

Open
snowyukitty wants to merge 2 commits into
pythonarcade:developmentfrom
snowyukitty:feat/sprite-list-draw-range
Open

snowyukitty wants to merge 2 commits into
pythonarcade:developmentfrom
snowyukitty:feat/sprite-list-draw-range

Conversation

@snowyukitty

@snowyukitty snowyukitty commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2231.

Add SpriteList.draw_range(start=0, stop=None, ...) so games can draw a contiguous portion of an existing sprite batch without creating another list. Bounds follow Python slicing, including negative indices, clipping and an exclusive stop; selected sprites retain list order.

Declare and document draw_range on the read-only SpriteSequence, following draw. SpriteList provides the rendering implementation, and consumers annotated as SpriteSequence can call it directly.

The buffer renderer uses the existing index-buffer offset. The texture renderer uses a shader instance offset and restores the shared uniform after rendering. Empty, invisible and transparent ranges keep lazy lists uninitialized. Filtering and blending options match draw(). Legacy texture shaders remain usable for ordinary drawing and zero-start ranges; a nonzero range requires sprite_start.

Validation on Linux / Python 3.12 / pyglet 3.0.dev11 with Mesa and Xvfb:

  • python -m pytest tests/unit -q: 1,665 passed, including actual pixel and Window/View regressions in both storage implementations.
  • A consumer typed as SpriteSequence[Sprite] type-checks; the same consumer fails with a missing-attribute error against the previous published interface.
  • Repository make.py format --check, ruff-check, mypy and pyright pass.
  • python make.py docs-full passes with warnings treated as errors, using prefetched intersphinx inventories.

Texture storage was exercised on native OpenGL. Browser/WebGL and controller hardware were not run locally.

@sjrd sjrd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method could be introduced in SpriteSequence, and documented there, like draw.

@snowyukitty

Copy link
Copy Markdown
Contributor Author

Updated in 6498500.

draw_range is now declared and documented on SpriteSequence, following draw; SpriteList provides the implementation. The renderer regression calls it through a SpriteSequence[Sprite] reference, and an explicitly typed consumer passes type checking.

The 1,665 native unit tests, repository formatting/lint/type checks, and full documentation build with warnings treated as errors pass locally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the ability to draw a sub-section of a spritelist

2 participants