I have a class (I'll call it with letter "A") and class B.

A is the object (as a character) and B is the rendering class which have the aim to show A.

I am looking for a way to detect when A is pressed, with normal InputProcessor I can't because it detect touch in the entire screen, I only want detect touch over the object. If I check touch position and "A" position it doesn't work because the object is moving and the values aren't so precise

How to solve?

this didn't solve for me :Efficient way of detecting a touched object in a game?. Here is explained "what to do" and not "how to do"

  • \$\begingroup\$ possible duplicate of Efficient way of detecting a touched object in a game? \$\endgroup\$
    – Pip
    May 8, 2015 at 19:47
  • \$\begingroup\$ @Pip It didn't help me \$\endgroup\$
    – user65825
    May 8, 2015 at 20:18
  • 2
    \$\begingroup\$ @user65825 In what way are the existing answers there insufficient? You could start a bounty to raise attention to it once you have 75 rep, but this question still looks pretty close to that one to me. \$\endgroup\$
    – Anko
    May 8, 2015 at 23:17

1 Answer 1


What you need to do is assign a listener to the Actor (I assume you are using these). This is as simple as (if you are trying to detect clicks):

myActor.addListener(new ClickListener() {
    public void clicked(args) {....

Then put whatever you want to happen in that clicked method. Make sure your game's input processor is that Stage! (Gdx.input.setInputProcessor(myStage))

  • \$\begingroup\$ I don't use Actor \$\endgroup\$
    – user65825
    May 8, 2015 at 23:57
  • \$\begingroup\$ @user65825 I would recommend using Scene2D, if you aren't too far along. But I can elaborate on this answer to cater toward non-Scene2D users if you want, just let me know. \$\endgroup\$ May 9, 2015 at 0:08
  • \$\begingroup\$ I am going to use this and I'll let you know the result. For now this is the best answer \$\endgroup\$
    – user65825
    May 9, 2015 at 10:28
  • \$\begingroup\$ I did what you said but it doesn't work, my touch isn't detected. pastebin.com/4tfUnWZs \$\endgroup\$
    – user65825
    May 10, 2015 at 16:59
  • \$\begingroup\$ @user65825 You haven't set your actor's size or position (although the default is 0, 0 so your current implementation can get away with that). \$\endgroup\$ May 10, 2015 at 17:32

Not the answer you're looking for? Browse other questions tagged .