How to know if an actor has been touched?

Anything libgdx related goes here!

How to know if an actor has been touched?

Postby dgame » Thu Jun 13, 2019 6:45 am

I touch the screen and I slide my finger without raising my finger some actors are touched by the way.
I tried with touchdown but only the first actor is selected.
How to do this?
thank you.
dgame
 
Posts: 8
Joined: Tue Nov 06, 2018 5:19 pm

Re: How to know if an actor has been touched?

Postby tenfour04 » Thu Jun 13, 2019 2:19 pm

Stage only sends touchDragged events to the single actor that accepted the touchDown event. So you will have to do this manually by cycling through all your actors. You can do this by subclassing Stage and overriding touchDragged() (don't forget to call super) or by making another InputProcessor and combining it with Stage in an InputMultiplexor.

In touchDragged, something like this:
Code: Select all
stage.screenToStageCoordinates(tmpVec2.set(screenX, screenY);
for (Actor actor : stage.getRoot().getChildren()){
    if (actor.hit(tmpVex2.x, tmpVec2.y, true) != null)
        //Do something
}
tenfour04
 
Posts: 1208
Joined: Sat Jun 18, 2011 3:24 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest