Hi there! I've been struggling with some collision problems in my game. I'm doing all my testing on 2.1.0 now, but I also saw this behavior in 2.0.3. After many hours of debugging, I decided to set up a separate, reduced test case. I'm still seeing the same issues there, so it seemed like time to file a bug report. Hopefully I'm just making some silly mistakes, but at this point I'm pretty sure there's something deeper going on.
- My test case repo: GitHub - paulstraw/pdAlphaTest
- A pre-built
- D-pad moves
- Hold B to move faster
- Crank changes arrow sprite
In short, there seems to be some unexpected behavior with both the alpha and AABB collision detection methods provided by the SDK. Specifically:
The pixel content of the images being compared seems to change the result of alpha collision methods (i.e.
playdate.graphics.sprite:alphaCollision) in unexpected ways.
There seem to be many things that can trigger this unexpected behavior. The simplest reproduction I've found is a full white or black image vs one with one (any?) clear pixel. In this gif, note how the pixel perfect collisions work as expected between the arrow and right hand square with one clear pixel (shown by the top right red text).
Collisions between the arrow and fully white square on the left are strange. They seem to work mostly normally against the top/bottom edges of the square. At the left/right sides, though, no alpha collision is reported until there's significant overlap.
It's difficult for me to tell exactly what's happening, but the lack of alpha collision reported seems to have something to do with the amount of vertical overlap the arrow has with the square? Note:
- How the trigger depth differs depending on the direction I approach from.
- The arrow sprite can be rotated with the crank (this is done via imagetable swap), and the trigger depth is symmetrical/consistently weird. The arrow sprite used makes no difference for alpha collision against the image with one clear pixel.
- Which pixel is clear doesn't seem to matter, just that some pixel is clear.
My game is using
playdate.graphics.checkAlphaCollision and tilemaps. I also set up the repro app that way initially (which you can see as of commit
a1bee162). However, the same issue can be reproduced with just normal sprites and the built in
:alphaCollision. This is much simpler (and removes a bunch of my code/math from the equation), so I updated the example.
This one seems like generally a less funky problem, but I'm still stumped. Note how the
collCount in the top right is reported as 1 correctly when I overlap each sprite individually. However, overlapping both at the same time still only shows 1:
Thanks for reading all that, hopefully it's not a waste of time. AND, thanks for making Playdate! It's been an absolute joy to build on.