kanoonsantikul
kanoonsantikul

Reputation: 199

How to detect when drag input is end in libgdx

I don't know how to detect when the user drag event is end or not so I decide to do like this

protected class Input extends DragListener{
    boolean dragging=false;

    @Override
    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
        return true;
    }

    @Override
    public void touchDragged(InputEvent event, float x, float y, int pointer) {
        if(!dragging)dragging=true;
            *my game logic*
            .
            .
            .
    }

    @Override
    public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
        Gdx.app.log("touch up","");
        if (dragging) {
            *my game logic*
            .
            .
            .
        }

    }
}

I try my class by drag and touch up ,nothing happen. I drag again and nothing happen. then I tap and the console is print "touchUp" two time. Is there anything else to detect it

Upvotes: 0

Views: 925

Answers (1)

Madmenyo
Madmenyo

Reputation: 8584

In the interface GestureListener that resides in GestureDetector there is a method pan and panStop. You should implement that interface, add all the methods from it and use pan for your dragging behaviour and panStop for the solution to your question. The methods register for both touch and mouse as well as multiple finger touches.

Upvotes: 1

Related Questions