How can I make LibGDX detect only one click / click?

I am trying to make a basic counter, so that each tap will increment the counter by one. I can make the counter work, but it also increases the number of madness when I hold with my finger / click.

The code:

public void render() {
    boolean isTouched = Gdx.input.isTouched();

    if (isTouched) {
        System.out.println(Cash);
        Cash++;

    }

}

Also, while I'm here, how can you print integer/float, which will change every time?

Like: font.draw(batch, Cash, 300, 260);

Doesn't work right.

+3
source share
2 answers

What you do is poll Input. But what do you want InputProcessor for :

public class MyInputProcessor implements InputProcessor {
   @Override
   public boolean keyDown (int keycode) {
      return false;
   }

   @Override
   public boolean keyUp (int keycode) {
      cash++; //<----
      return false;
   }

   @Override
   public boolean keyTyped (char character) {
      return false;
   }

   @Override
   public boolean touchDown (int x, int y, int pointer, int button) {
      return false;
   }

   @Override
   public boolean touchUp (int x, int y, int pointer, int button) {
      return false;
   }

   @Override
   public boolean touchDragged (int x, int y, int pointer) {
      return false;
   }

   @Override
   public boolean touchMoved (int x, int y) {
      return false;
   }

   @Override
   public boolean scrolled (int amount) {
      return false;
   }
}

Define it in your code:

MyInputProcessor inputProcessor = new MyInputProcessor();
Gdx.input.setInputProcessor(inputProcessor);

Link: Event handling in the viking Libgdx

/float, ?

: font.draw(, Cash, 300, 260);
.

BitmapFont # draw , int/float. :

Integer.toString(Cash); //or
Float.toString(Cash);

Pro : Caps. cash.

+5

InputProcessor - , , ( , , , , "justTouched" API:

if (Gdx.input.justTouched()) {
    System.out.println(Cash);
    Cash++;
}

. https://code.google.com/p/libgdx/wiki/InputPolling

+3

All Articles