libgdx – Check if body is touch

| | August 4, 2015

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?

One Response to “libgdx – Check if body is touch”

  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) {

Leave a Reply