Sw3das
Sw3das

Reputation: 157

LibGDX - Is actor touched in radius

I'm trying to add Actor to Stage and that actor image's shape is Circle. I want to detect the touch only in that circle not the rectangle. How could I accomplish that ?

A bit of backstory:
I had made UI from Sprites, and it was working fine. But now I want to change that system to Scene2D.UI ( it's easier to manipulate this way ( at least for me ) ).

Thanks in advance!

Upvotes: 1

Views: 137

Answers (1)

Sw3das
Sw3das

Reputation: 157

Found the solution myself!

You just need to @Override the Actor's hit method, like so:

@Override public Actor hit( float x, float y, boolean touchable )
{
    if( touchable && getTouchable( ) != Touchable.enabled ) return null;
    return area.contains( x, y ) ? this : null;
}

P.S. area is a Circle class object, defined in the Constructor

Upvotes: 3

Related Questions