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\$
  • \$\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 '15 at 20:38
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();
        }
    });
}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Where Have I call the addTouchListener() function? \$\endgroup\$ – mugimugi Aug 1 '15 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.