gestures - Determining a fling from a pan in libgdx -
i'm developing game libgdx , i'm having trouble determining fling
pan
.
my gesturelistener
:
@override public boolean fling(float velocityx, float velocityy, int button) { //if (velocityx > 1000f) { // can use exclude slow pans executing fling system.out.println("flinged - velocityx: " + velocityx + ", button: " + button); //} return false; } @override public boolean pan(float x, float y, float deltax, float deltay) { // there doesn't seem way have not fire on fling system.out.println("panned - deltax: " + deltax); return false; } @override public boolean panstop(float x, float y, int pointer, int button) { system.out.println("pan stop - pointer: " + pointer + ", button: " + button); return false; }
the problem if both pan
, fling
fire. understand fling
fast pan
, need able determine between 2 gestures can handle each 1 separately.
a succinct way of asking is, how provide unique actions fling
, pan
?
the reasonable solution in opinion use longpress
set boolean flag 'enter panning mode' when swiping without long press making fling.
this how see this:
//the flag checking if pan mode entered boolean pan = false; @override public boolean longpress(float x, float y) { pan = true; return false; } @override public boolean fling(float velocityx, float velocityy, int button) { if(!pan) { system.out.println("flinged - velocityx: " + velocityx + ", button: " + button); } return false; } @override public boolean pan(float x, float y, float deltax, float deltay) { if(pan) { system.out.println("panned - deltax: " + deltax); } return false; } @override public boolean panstop(float x, float y, int pointer, int button) { if(pan) { pan = false; system.out.println("pan stop - pointer: " + pointer + ", button: " + button); } return false; }
of course if longpress
long purposes can change using setlongpressseconds(float longpressseconds)
method of gesturedetector instance