Only show overlapping portion of shape (LibGDX)

So I’m stuck again Hopefully someone can help

I’m working on my first app, a 2d side-scroller. It’s a bat in a cave and he will shoot out a Circle shaped sonar. I want this circle to be generally invisible and only show the parts of it that are overlapping my triangular “Polygon” objects (cave spikes). I looked through the LibGDX documentation and had trouble finding a way of locating coordinates of the point where shapes are overlapping. Any quick tips would be awesome to get me in the right direction.

You could always do a mask. Basically, you invert the screen-- Locations with triangles become gaps and gaps gain triangles-- then you set up layers such that (From near camera to furtherest): Player/UI (Very top/always visible objects), Mask (As described), the Sonar, the spikes (If you have a reason to draw them at all, I mean.)

This is probably the easiest method. And I use that term lightly. Alternately, you can try something involving polygon clipping (But a circle can be a PITA because it’s either not a real polygon or it’s a polygon with infinite vertices-- Or just a bunch): http://en.wikipedia.org/wiki/Weiler-Atherton_clipping_algorithm

Thanks for your reply! The way you described masking sounds like exactly what I’m going for. Just having some trouble finding more information on the topic. Will keep looking.

This can be done using shader. Just use center and R of sonar as a parameter. This is if you want use precise calculation. In other hand if it is your first game just simplify this problem.

  1. You can calculate distance for each vertex and interpolate values inside triangle.
  2. You can draw cave spike if it’s center inside a sonar circle.