Detect Rotated Sprite Overlaping

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:

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!

I think you should try what you've found.

  • the collide rect can simply be big enough to encompass all rotations footprint
  • or you can store a different collide rect per frame
  • or roll your own collision function

Then, once you know there's a ballpark collision, you can do a more accurate but slower check with:

1 Like

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.


Thanks to both of you! I went for Matt's solution of making the collider bigger to cover the whole sprite rotation. And in the event I ask for the method


function MyClass:collisionResponse(other)
    if self:alphaCollision(other) then
        return gfx.sprite.kCollisionTypeFreeze
        return gfx.sprite.kCollisionTypeOverlap

This seems to work great!
Thank you!