Skip to content

Commit 97f3bb9

Browse files
committed
Improve spritecollideany function
1 parent 09e70e1 commit 97f3bb9

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src_py/sprite.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,19 +1751,16 @@ def spritecollideany(sprite, group, collided=None):
17511751
sprites must have a "rect" value, which is a rectangle of the sprite area,
17521752
which will be used to calculate the collision.
17531753
1754-
17551754
"""
1756-
# pull the default collision function in as a local variable outside
1757-
# the loop as this makes the loop run faster
1758-
default_sprite_collide_func = sprite.rect.colliderect
1759-
17601755
if collided is not None:
17611756
for group_sprite in group:
17621757
if collided(sprite, group_sprite):
17631758
return group_sprite
17641759
else:
1765-
# Special case old behaviour for speed.
1760+
# pull the default collision function in as a local variable outside
1761+
# the loop as this makes the loop run faster
1762+
sprite_rect_collide = sprite.rect.colliderect
17661763
for group_sprite in group:
1767-
if default_sprite_collide_func(group_sprite.rect):
1764+
if sprite_rect_collide(group_sprite.rect):
17681765
return group_sprite
17691766
return None

0 commit comments

Comments
 (0)