Java Code Examples for com.badlogic.gdx.scenes.scene2d.utils.DragListener

The following examples show how to use com.badlogic.gdx.scenes.scene2d.utils.DragListener. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dice-heroes   Source File:    License: GNU General Public License v3.0 5 votes vote down vote up
public ViewScroller(ViewController viewController) {
    this.viewController = viewController;
    stage =;
    root = viewController.root;

    hScrollEnabled = root.getWidth() > stage.getWidth() - LEFT - RIGHT;
    vScrollEnabled = root.getHeight() > stage.getHeight() - BOTTOM - TOP;

    minRootX = stage.getWidth() - RIGHT - root.getWidth();
    maxRootX = LEFT;
    minRootY = stage.getHeight() - TOP - root.getHeight();
    maxRootY = BOTTOM;

    stage.addListener(listener = new DragListener() {

        @Override public void drag(InputEvent event, float x, float y, int pointer) {
            if (!enabled)
            if (!event.getTarget().isDescendantOf(root) && event.getTarget() != stage.getRoot())
            if (hScrollEnabled) root.setX(MathUtils.clamp(root.getX() - getDeltaX(), minRootX, maxRootX));
            if (vScrollEnabled) root.setY(MathUtils.clamp(root.getY() - getDeltaY(), minRootY, maxRootY));