libgdx演员touchHandling问题 [英] libgdx actor touchHandling issue

查看:208
本文介绍了libgdx演员touchHandling问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经前张贴了这个问题,但似乎我的标题无处即使我没收到许多人的帮助。因此,我做了一个小实验。我创建了一个测试项目只是为了测试出LibGdx触摸操控。这touchTester项目在某种程度上复制了我的问题。附后(附件切除),请找到整个项目源$ C ​​$ C(压缩文件)。在以下code中的加计数器应该只返回1,因为它应该只需要运行一次。

I have posted this question before but it seems that I am heading nowhere even though I did receive help from many people. Therefore I have done a small experiment. I have created a test project just to test out the LibGdx touch handling. This touchTester project somehow replicates my problem. Attached (attachment removed) please find the entire project source code (zipped file). The upCounter in following code should only return 1 since it should only be needed to run once.

// upCounter is = 0;        
this.libgdxImg.addListener(new InputListener() {
    public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
    return true;
}

public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
    upCounter++;
    touchtester.doLog("upCounter = " + upCounter);
    }
});

然而,当我运行它,它给了我这样的结果。

However, when I run it, it give me this result

catland: touchTester: render
catland: touchTester: render
catland: touchTester: upCounter = 1
catland: touchTester: upCounter = 2
...
catland: touchTester: upCounter = 94
catland: touchTester: upCounter = 95
catland: touchTester: render
catland: touchTester: render

我可以问别人的帮助来试一下吗?我完全不知道问题出在哪里来的。我安装使用GDX-设置-ui.jar文件我的项目。

May I ask someone's help to test it out? I have absolutely no idea where the problem came from. I setup my project using the gdx-setup-ui.jar file.

推荐答案

您错过了这里最重要的部分。给定的code其中您添加新InputListener ... 里面的渲染()方法。

You missed the most important part here. The given code where you add your new InputListener... is inside your render() method.

这不是应该的。它通常做的是在每一帧中添加一个新的,匿名的 InputListener 你的形象。所有这些听众将得到通知,并都加1到你的加计数器。移动code到你的显示()方法和你预期它应该工作。

That's not how it should be. What it basically does is adding a new, anonymous InputListener to your image in every single frame. All those listeners will get notified and they all add 1 to your upcounter. Move the code to your show() method and it should work as you expected.

这篇关于libgdx演员touchHandling问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆