Search code examples
javalibgdxscene2d

Scene2d: Circular hitbox for an actor


Is there a way to make an Actors hitbox beeing circular. Or if for example add an Inputlistener and check if the touch point is inside the circle or else pass the input to the next actor that would be hit.

Its important for me if the hit is not in the circle but in the bounds of the actor, the event passes to the next actor that would be hit.


Solution

  • Dario, add a com.badlogic.gdx.math.Circle to the Actor. Then, as you suggested, add an InputListener and use Circle.contains(float x, float y) to determine whether the touched coordinates are within the Circle. If you'd like the touch event to be captured before hitting the regular rectangular hitbox, use Actor.addCaptureListener for adding your InputListener.