Skip to content

Commit 04ae809

Browse files
committed
Add method 0 for auto-select to check_for_collision_with_lists
1 parent 539dd7e commit 04ae809

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

arcade/sprite_list/collision.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def check_for_collision_with_list(
196196
def check_for_collision_with_lists(
197197
sprite: BasicSprite,
198198
sprite_lists: Iterable[SpriteSequence[SpriteType]],
199-
method=1,
199+
method=0,
200200
) -> list[SpriteType]:
201201
"""
202202
Check for a collision between a Sprite, and a list of SpriteLists.
@@ -207,8 +207,16 @@ def check_for_collision_with_lists(
207207
sprite_lists:
208208
SpriteLists to check against
209209
method:
210-
Collision check method. 1 is Spatial Hashing if available,
211-
2 is GPU based, 3 is slow CPU-bound check-everything. Defaults to 1.
210+
Collision check method. Defaults to 0.
211+
212+
- 0: auto-select. (spatial if available, GPU if 1500+ sprites, else simple)
213+
- 1: Spatial Hashing if available,
214+
- 2: GPU based
215+
- 3: Simple check-everything.
216+
217+
Note that while the GPU method is very fast when you cannot use spatial hashing,
218+
it's also very slow if you are calling this function many times per frame.
219+
What method is the most appropriate depends entirely on your use case.
212220
213221
Returns:
214222
List of sprites colliding, or an empty list.
@@ -224,9 +232,10 @@ def check_for_collision_with_lists(
224232
sprites_to_check: Iterable[SpriteType]
225233

226234
for sprite_list in sprite_lists:
227-
if sprite_list.spatial_hash is not None and method == 1:
235+
# Spatial
236+
if sprite_list.spatial_hash is not None and (method == 1 or method == 0):
228237
sprites_to_check = sprite_list.spatial_hash.get_sprites_near_sprite(sprite)
229-
elif method == 3:
238+
elif method == 3 or (method == 0 and len(sprite_list) <= 1500):
230239
sprites_to_check = sprite_list
231240
else:
232241
# GPU transform

0 commit comments

Comments
 (0)