Java ActorGestureListener Fling未注册
我无法让我的应用程序注册对特定演员的放纵行为。我在向演员添加一个简单的Java ActorGestureListener Fling未注册,java,input,libgdx,Java,Input,Libgdx,我无法让我的应用程序注册对特定演员的放纵行为。我在向演员添加一个简单的点击并检查桌子上是否有点击时没有问题。对flick做同样的事情,但它不起作用。我错过什么了吗?在网上到处都能看到,关于ActorGestureListener的恋情信息不多 我的代码: mainLeftTable.setTouchable(Touchable.enabled); mainLeftTable.addListener(new ActorGestureListener(){ @Over
点击并检查桌子上是否有点击时没有问题。对flick做同样的事情,但它不起作用。我错过什么了吗?在网上到处都能看到,关于ActorGestureListener的恋情信息不多
我的代码:
mainLeftTable.setTouchable(Touchable.enabled);
mainLeftTable.addListener(new ActorGestureListener(){
@Override
public void fling(InputEvent event, float velocityX, float velocityY, int button) {
System.out.println(velocityX + " - " + velocityY);
}
});
使用此代码不会发生任何事情,我看不出我缺少了什么
作为参考,设置tap
可使用以下代码:
mainLeftTable.setTouchable(Touchable.enabled);
mainLeftTable.addListener(new ActorGestureListener(){
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
System.out.println("tapped");
}
我有我的舞台作为输入处理器
更新:
显然是ScrollPane中的某些东西把它搞砸了,如果我在我的桌子上禁用了ScrollPane,fling就会工作。为什么会这样?我需要滚动条您是否正在向Gdx应用程序介绍侦听器?即:
Gdx.input.setInputProcessor(yourListener)
向应用程序介绍您的新侦听器?如果您有多个侦听器,则可能需要使用输入多路复用器。不确定如何使用“点击”侦听器设置其余代码
我进行了快速搜索,并浏览了以下教程,其中可能会给出一个示例,您可以将其重新用于代码:
编辑:
根据评论,下面是一个示例应用程序。我想这就是你想要做的
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;
public class Fling implements ApplicationListener {
private Texture music;
private SpriteBatch batch;
private OrthographicCamera camera;
private Stage stage;
@Override
public void create() {
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
batch = new SpriteBatch();
music = new Texture(Gdx.files.internal("img/sprites/buttons/music_off.png"));
Image image = new Image(music);
Table actor = new Table();
actor.debug();
actor.add(image).width(105).height(105);
actor.setX(100);
actor.setY(100);
actor.setTouchable(Touchable.enabled);
actor.addListener(new ActorGestureListener(){
@Override
public void fling(InputEvent event, float velocityX, float velocityY, int button) {
System.out.println(velocityX + " - " + velocityY);
}
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
System.out.println("tapped");
}
@Override
public void touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("touchdown");
}
});
stage = new Stage();
stage.addActor(actor);
Gdx.input.setInputProcessor(stage);
}
@Override
public void render() {
stage.draw();
}
@Override
public void dispose() {
music.dispose();
batch.dispose();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}
当我运行它时,我看到:
我也遇到了同样的问题,在检查滚动窗格的源代码后,我注意到ActorGestureListener已经处理了fling事件并自动取消触摸焦点
只需在滚动窗格上调用setCancelTouchFocus(false),您就可以自己处理fling事件。至少这解决了我的问题。问题是,我不需要像这样添加侦听器。我非常了解如何设置输入处理器和/或多路复用器。但是,由于其他每一个动作都有效,我觉得我错过了一些其他的东西,这只是“扔”而已,没有任何作用。好的,谢谢你添加额外的代码和说明。我以前使用过手势适配器,而不是ActorGestureListener,而且对fling没有任何问题。我在这里尝试了一些方法,但无法复制您的设置。除非你想发布更多的代码,否则我会让其他人尝试回答。谢谢你的尝试。我不知道还有什么代码是相关的。不幸的是,我不能像这样使用GestureAdapter,那么我必须像你说的那样使用多路复用器。我可能会这样做,但我想看看是否还有其他我可以做的事情:)奇怪的是,我放弃了我之前所做的,创建了一个barebones类来实现应用程序侦听器,复制并粘贴ActorGestureListener的代码,所有工作都很好-touch/tap/fling-我看到了你的println。没有手势适配器。只有阶段作为输入处理器。我几天前才加入的。不确定礼仪或最佳实践是什么。我有大约80行代码和屏幕截图来显示一个工作版本,但不确定这是否对你有帮助。我喜欢你发布你的工作解决方案。也许我能找到我错过的东西:)