问题描述
我是 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?
推荐答案
我已经成功解决了这个问题,没有池化概念.
I've succeeded to work this out, without pooling concept.
我有自定义 InputProccesor,int 我使用过类似的逻辑,如 P.T.提及.我 touchDown 我启动了发射子弹的线程并进行一些计算,因为我从 Renderer 类中访问了一些我必须使用的方法
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<Result> field of the ApplicationListener.
shootBullet(screenX, screenY);
}
});
为了避免 OpenGL 上下文异常.
To avoid OpenGL context exception.
在touchUp方法中我取消了拍摄线程.
In touchUp method I cancel shooting thread.
Tnx 的想法!
这篇关于libgdx touchDown 只调用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!