Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgdx touchDown called just once

Tags:

libgdx

I'm new to LibGdx, and have problem with input handling.

My player needs to shoot bullets whenever touch is down. But it seems that this method is called just once...

And then user have to click again to shoot another bullet.

I want always to shoot bullets while click is down...

Is there a way to handle this use case?

like image 361
Veljko Avatar asked Dec 26 '22 07:12

Veljko


1 Answers

Look into "polling" on the touch input, instead of getting Input events. So, in your render or update method, use something like this:

 boolean activeTouch = false;

 if (Gdx.input.isTouched(0)) {
    if (activeTouch) {
       // continuing a touch ...
    } else {
       // starting a new touch ..
       activeTouch = true;
    }     
 } else {
    activeTouch = false;
 }
like image 177
P.T. Avatar answered Feb 27 '23 04:02

P.T.