libgdx touchDown called just once

前端 未结 3 1534
孤街浪徒
孤街浪徒 2021-01-19 04:03

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.

3条回答
  •  轮回少年
    2021-01-19 04:43

    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;
     }
    

提交回复
热议问题