To create collision detection that not AABB, do I need to create an AABB big enough to cover it all and then test for transparent sprites?
Sounds like a pretty good idea to me.
You can do it that way, but it will be very slow.
Collision detection is just math basically. The CPU is very fast when calculating pure math.
Testing for transparent sprites involves reading from memory (alpha values of the textures). Accessing memory is at least an order of magnitude slower than just doing math.
I would guess you will only manage checking a handful of objects while maintaining 30fps+ (while also drawing and calculating your general game logic).
Now you have multiple ways around this:
- The library contains a function for checking polygon to polygon intersections: playdate.geometry.polygon:intersects(p). This will not work well for circles though (you would have to model them as polygons as well). This also does not help you, if you need collision resolution (i.e. not just hit detection, but things sliding around and off each other)
- There is a port of Box2D (a "professional" physics library): Playbox2d (port of box2d lite physics engine to C and Playdate SDK). This might be overkill though, depending on the game you want to develop.
- Then there is also my library: GitHub - foxblock/pd-sat-collision: SAT-based 2D collision checking for the Playdate. With a lengthy write-up here: Collision checking library (a tale of reinventing the wheel and fighting the garbage collector) (you can skip this, if you don't care for benchmarks and implementation details).
My library is a C implementation of a collision checking algorithm called Separating Axis Theorem (SAT). There is also a Lua version in the repository, which might be "good enough", if you only have a couple of entities.
I have not gotten around to writing much documentation, but the repository contains an example project, which you can copy to get started and see how the library is used. The library currently only supports circles and polygons (so you have to model the rectangles as polygons).
If you end up trying it out and have any troubles, feel free to ask.
I didn't know about polygon intersection. That might be what I need.
I'll have a play. Thanks.