I have some bodies around the screen(Ball[] balls), and I would like to delete them when user touches them.

Also, I have an Image as userData of the bodies.

I dont want to make a function to all Image, because the balls have to be deleted in an order.

What is the best way to detect if a body is touch?

  • \$\begingroup\$ Why use a array? You might be better off using a list. Click ball -> call dispose on image -> remove from list. \$\endgroup\$
    – Madmenyo
    Aug 2, 2015 at 20:38

1 Answer 1


Your best bet is to extend the Image class and add a touch listener.

Add this code into your Image subclass:

private void addTouchListener() {
    this.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
  • \$\begingroup\$ Where Have I call the addTouchListener() function? \$\endgroup\$
    – mugimugi
    Aug 1, 2015 at 22:42

You must log in to answer this question.

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