Inner workings of overlappingSprites()

, ,

Hi,
I'm trying to improve the performance of my game and the sampler shows a lot of time is spent on the playdate.graphics.sprite:overlappingSprites() method. I was trying to check the CoreLibs code to check how it is implemented to see if I could simplify it to fit my needs, but unfortunately the code of that method is not available.
Is there a way to check how that method is implemented?

Thanks in advance for your help.

There isn't a way to look at the code directly, as the method is implemented as part of the firmware for speed reasons, but yes, as you've noticed this can be a fairly computationally-intense method.

Internally we have some optimizations (for example, we organize areas of the drawing space into buckets so we don't have to check sprites that could not possibly be overlapping, using hash tables to keep track of which sprites are in which buckets), but in the worst case the code essentially has to loop over every other sprite to check for overlapping collision rects (taking into account group masks, etc).

For that reason, I would not recommend you use this method in a critical section of your code. The other sprite collision methods should be much more efficient if you can use any of those instead.

Hey Dan.
It seems that my best course of action is refactoring my implementation to use the other methods since I'm using it inside the update() loop :grimacing:

Thanks for your help.

Hey Dan.
I'm trying to find an alternative to overlappingSprites(), my first idea is to use checkCollisions(self.x, self.y) but I'm curious to know if at the end the underlying implementation will do the same amount of work.
I'm trying to imagine the underlying algorithm and they should be doing the same, right?
Do you have any insights?
Thanks in advance for your help.