问题
Is there an equivalent in libGdx (in Android) like the touchdown event - so when a user touches the screen (and holds their finger down continuously),i.e. touchhelddown method?
回答1:
You can use GestureDetector. It implements InputAdapter
so you can use it instead of your InputAdapter or along with your InputAdapter using InputMultiplexer
.
You need to provide a GestureListener
to it. GestureDetector calls GestureListener's methods when it detects supported gestures. These methods and gestures are:
public boolean touchDown (int x, int y, int pointer);
public boolean tap (int x, int y, int count);
public boolean longPress (int x, int y);
public boolean fling (float velocityX, float velocityY);
public boolean pan (int x, int y, int deltaX, int deltaY);
public boolean zoom (float originalDistance, float currentDistance);
public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer,
Vector2 firstPointer, Vector2 secondPointer);
You can extend GestureAdapter
and override the method you are interested in. In your case you will override longPress
method. You can also provide longPressDuration
as a parameter to constructor.
来源:https://stackoverflow.com/questions/10065467/touchdown-held-down-libgdx