Skip to content

Commit fcc4cc6

Browse files
authored
Merge pull request #2036 from pygame-community/sprite-deprecations
Undocument and deprecate redundant sprite group classes
2 parents aff289d + b345f6f commit fcc4cc6

File tree

3 files changed

+29
-60
lines changed

3 files changed

+29
-60
lines changed

docs/reST/ref/sprite.rst

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ Sprites are not thread safe. So lock them yourself if using threads.
203203
204204
A simple container for Sprite objects. This class can be inherited to create
205205
containers with more specific behaviors. The constructor takes any number of
206-
Sprite arguments to add to the Group. The group supports the following
206+
Sprite arguments to add to the Group. All sprites in groups are stored in the
207+
order they were added to the group. The group supports the following
207208
standard Python operations:
208209

209210
::
@@ -297,8 +298,7 @@ Sprites are not thread safe. So lock them yourself if using threads.
297298
``Sprite.image`` attribute for the source surface, and ``Sprite.rect``
298299
for the position.
299300

300-
The Group does not keep sprites in any order, so the draw order is
301-
arbitrary.
301+
The Group keeps sprites in the order they were added, they will be drawn in this order.
302302

303303
.. ## Group.draw ##
304304
@@ -337,22 +337,6 @@ Sprites are not thread safe. So lock them yourself if using threads.
337337
338338
.. ## pygame.sprite.Group ##
339339
340-
.. class:: RenderPlain
341-
342-
| :sl:`Same as pygame.sprite.Group`
343-
344-
This class is an alias to ``pygame.sprite.Group()``. It has no additional functionality.
345-
346-
.. ## pygame.sprite.RenderClear ##
347-
348-
.. class:: RenderClear
349-
350-
| :sl:`Same as pygame.sprite.Group`
351-
352-
This class is an alias to ``pygame.sprite.Group()``. It has no additional functionality.
353-
354-
.. ## pygame.sprite.RenderClear ##
355-
356340
.. class:: RenderUpdates
357341

358342
| :sl:`Group sub-class that tracks dirty updates.`
@@ -380,18 +364,6 @@ Sprites are not thread safe. So lock them yourself if using threads.
380364
381365
.. ## pygame.sprite.RenderUpdates ##
382366
383-
.. function:: OrderedUpdates
384-
385-
| :sl:`RenderUpdates sub-class that draws Sprites in order of addition.`
386-
| :sg:`OrderedUpdates(*sprites) -> OrderedUpdates`
387-
388-
This class derives from ``pygame.sprite.RenderUpdates()``. It maintains the
389-
order in which the Sprites were added to the Group for rendering. This makes
390-
adding and removing Sprites from the Group a little slower than regular
391-
Groups.
392-
393-
.. ## pygame.sprite.OrderedUpdates ##
394-
395367
.. class:: LayeredUpdates
396368

397369
| :sl:`LayeredUpdates is a sprite group that handles layers and draws like OrderedUpdates.`

src_c/doc/sprite_doc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818
#define DOC_SPRITE_GROUP_DRAW "draw(Surface) -> List[Rect]\nblit the Sprite images"
1919
#define DOC_SPRITE_GROUP_CLEAR "clear(Surface_dest, background) -> None\ndraw a background over the Sprites"
2020
#define DOC_SPRITE_GROUP_EMPTY "empty() -> None\nremove all Sprites"
21-
#define DOC_SPRITE_RENDERPLAIN "Same as pygame.sprite.Group"
22-
#define DOC_SPRITE_RENDERCLEAR "Same as pygame.sprite.Group"
2321
#define DOC_SPRITE_RENDERUPDATES "RenderUpdates(*sprites) -> RenderUpdates\nGroup sub-class that tracks dirty updates."
2422
#define DOC_SPRITE_RENDERUPDATES_DRAW "draw(surface) -> Rect_list\nblit the Sprite images and track changed areas"
25-
#define DOC_SPRITE_ORDEREDUPDATES "OrderedUpdates(*sprites) -> OrderedUpdates\nRenderUpdates sub-class that draws Sprites in order of addition."
2623
#define DOC_SPRITE_LAYEREDUPDATES "LayeredUpdates(*sprites, **kwargs) -> LayeredUpdates\nLayeredUpdates is a sprite group that handles layers and draws like OrderedUpdates."
2724
#define DOC_SPRITE_LAYEREDUPDATES_ADD "add(*sprites, **kwargs) -> None\nadd a sprite or sequence of sprites to a group"
2825
#define DOC_SPRITE_LAYEREDUPDATES_SPRITES "sprites() -> sprites\nreturns a ordered list of sprites (first back, last top)."

src_py/sprite.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,24 @@ def __init__(self, *sprites):
655655
self.add(*sprites)
656656

657657

658-
RenderPlain = Group
659-
RenderClear = Group
658+
class RenderPlain(Group):
659+
def __init__(self, *sprites):
660+
super().__init__(*sprites)
661+
warn(
662+
"This class will be removed in version 2.4.0",
663+
DeprecationWarning,
664+
stacklevel=2,
665+
)
666+
667+
668+
class RenderClear(Group):
669+
def __init__(self, *sprites):
670+
super().__init__(*sprites)
671+
warn(
672+
"This class will be removed in version 2.4.0",
673+
DeprecationWarning,
674+
stacklevel=2,
675+
)
660676

661677

662678
class RenderUpdates(Group):
@@ -690,31 +706,15 @@ def draw(self, surface):
690706

691707

692708
class OrderedUpdates(RenderUpdates):
693-
"""RenderUpdates class that draws Sprites in order of addition
694-
695-
pygame.sprite.OrderedUpdates(*sprites): return OrderedUpdates
696-
697-
This class derives from pygame.sprite.RenderUpdates(). It maintains
698-
the order in which the Sprites were added to the Group for rendering.
699-
This makes adding and removing Sprites from the Group a little
700-
slower than regular Groups.
701-
702-
"""
703-
704709
def __init__(self, *sprites):
705-
self._spritelist = []
706-
RenderUpdates.__init__(self, *sprites)
707-
708-
def sprites(self):
709-
return self._spritelist.copy()
710-
711-
def add_internal(self, sprite, layer=None):
712-
RenderUpdates.add_internal(self, sprite)
713-
self._spritelist.append(sprite)
714-
715-
def remove_internal(self, sprite):
716-
RenderUpdates.remove_internal(self, sprite)
717-
self._spritelist.remove(sprite)
710+
super().__init__(*sprites)
711+
warn(
712+
"OrderedUpdates is now just an alias to RenderUpdates, order of "
713+
"sprites is now maintained in all sprite Group classes. This "
714+
"class will be removed in version 2.4.0",
715+
DeprecationWarning,
716+
stacklevel=2,
717+
)
718718

719719

720720
class LayeredUpdates(AbstractGroup):

0 commit comments

Comments
 (0)