1
\$\begingroup\$

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?

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

1 Answer 1

0
\$\begingroup\$

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() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            YourClassName.this.wasTouched();
        }
    });
}
\$\endgroup\$
1
  • \$\begingroup\$ Where Have I call the addTouchListener() function? \$\endgroup\$ Commented Aug 1, 2015 at 22:42

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.