libgdx touchDown called just once

前端 未结 3 1483
孤街浪徒
孤街浪徒 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:45

    I've succeeded to work this out, without pooling concept.

    I have custom InputProccesor, int I've used similar logic like P.T. mentioned. I touchDown I start thread that shoots bullets and do some calculation, because I access to some methods from Renderer class I've to use

       Gdx.app.postRunnable(new Runnable() {
            @Override
            public void run() {
            // process the result, e.g. add it to an Array field of the ApplicationListener.
            shootBullet(screenX, screenY);
            }
        });
    

    To avoid OpenGL context exception.

    In touchUp method I cancel shooting thread.

    Tnx for idea!

提交回复
热议问题