Reputation: 121
I'm working on a game, and I would want the player to be able to increase the speed by double tapping the screen, my problem: Since the player moves by pressing the screen once (you press to the left to move left, and right to move right) will there be a delay for the program to see if the screen was pressed once or twice, or will the player first start by going normal speed, then speed up if it detects another tap? This is how my movement looks atm:
touchPos.set(Gdx.input.getX() - 42, Gdx.input.getY() + 19, 0);
camera.unproject(touchPos);
if (Gdx.input.isTouched()) {
if (player.getX() > touchPos.x + 16) {
player.setPosition(player.getX() - (speed * Gdx.graphics.getDeltaTime()), player.getY() + (130 * Gdx.graphics.getDeltaTime()));
} else if (player.getX() < touchPos.x - 16) {
player.setPosition(player.getX() + (speed * Gdx.graphics.getDeltaTime()), player.getY() + (130 * Gdx.graphics.getDeltaTime()));
}
And this works just fine, but how should I implement so the player can speed up with a simple gesture? Thoughts? (let me know if I need to elaborate, or post more code)
Upvotes: 0
Views: 1790
Reputation: 3562
Libgdx already has a GestureDetector class for detecting gestures. You can find more information about it on LibGdx wiki.
https://github.com/libgdx/libgdx/wiki/Gesture-detection
Note: GestureDetector needs to be registered as InputProcessor in order to detect gestures. If you want to keep your previous inout processor and also use GestureDetector, you will have to register both as InputProcessors by using an InputMultiplexer. More information can be found on this wiki page.
https://github.com/libgdx/libgdx/wiki/Event-handling
Upvotes: 1