zaxrsa
Last Updated: July 19, 2019
·
1.264K
· exallium

Gestures on a Table in LibGDX...

This took me longer than I care to admit.

1) Extend ActorGestureListener and implement whichever events you want

2) Set this as a listener on your table with addListener(..)

3) Use setTouchable(..) to set table to Touchable.enabled

4) Set the bounding box using setBounds(x, y, w, h)

5) Profit!

Ex:

class MyGestureListener extends ActorGestureListener {

    @Override
    public void fling(InputEvent event, float velocityX, float velocityY, int button) {
        // Do stuff...
    }
}

// Later on
Table myTable = new Table();
myTable.addListener(new MyGestureListener());
myTable.setTouchable(Touchable.enabled);
myTable.setBounds(x, y, w, h);

// Even Later.... PROFIT...