Hello!
I have a script that is giving me a lot of headaches.
I have 2 sprites that I need to know if they collide at some point. My problem is that both sprites have a rotation, and as far as I have been able to check, you can't rotate a collider.
It occurred to me to check if both sprites are overlapping. Checking the documentation, I found this method:
playdate.graphics.sprite:overlappingSprites()
But according to the documentation, it only works if the sprites have a collide rects. So I still have the same problem.
Is there any method in the SDK or any simple trick to solve this? And if this overlapping takes into account the transparencies of the sprites, even better!
Thanks!
You could calculate the “rotated rectangle” vertices and store them as a gfx.polygon in a custom attribute in the sprite object. Then use polygon:intersects(otherpoly) to detect collision.
You could do that every frame, or you could set a maximum bounding box and do the poly check only if that initial tripwire goes off.
class("MyClass").extends(gfx.sprite)
function MyClass:collisionResponse(other)
if self:alphaCollision(other) then
return gfx.sprite.kCollisionTypeFreeze
else
return gfx.sprite.kCollisionTypeOverlap
end
end