0

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)

user3486059
  • 121
  • 1
  • 1
  • 13
  • you can use swipe-up to increase the speed and swipe-down to decrease the speed. [see this post](http://stackoverflow.com/q/937313/3326331) for help related to gestures. if you are ok with swipe-up and swipe-down shall i post some code? – Sagar Pilkhwal Sep 03 '14 at 18:14
  • hmm, that might work, but I only want the increase in speed to be for like a second (to get out of a sticky situation), so it would be neat if one could doubletap to go fast, and tap one time to go normal. Is it possible to swipe sideways? that'd be cool – user3486059 Sep 03 '14 at 20:49
  • yes you can swipe in all directions..[this post](http://stackoverflow.com/a/938657/3326331) talks about swiping right to left and left to right. – Sagar Pilkhwal Sep 04 '14 at 05:59
  • Thanks alot dude! If u have any tips on how to code this it would be a great help, because it's not the same as in a normal android app when using libgdx, is it? I'm implementing 'screen' in my class, not Activity, or OnClickListener.. but I'm sure I'll figure it out in the end, just, it would help :) – user3486059 Sep 04 '14 at 14:29

1 Answers1

1

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

Zohaib Amir
  • 3,482
  • 2
  • 11
  • 29