LibGdx ScrollPane拦截投掷而不传递给其他侦听器

时间:2014-07-13 14:35:10

标签: java events libgdx gestures scrollpane

我使用整页大小的ScrollPane来显示我的选项菜单 它只有一整页的选项滚动工作正常,但自从从整页表格改为ScrollPane后,我再也无法获得投掷活动。

我在页面上有一个GestureDetector和一个舞台。它们是使用输入多路复用器添加的 当检测到x轴上的投掷,即向左或向右滑动时,我用它来触发返回主菜单

不幸的是,因为我开始使用ScrollPane,它似乎拦截了fling事件而没有将它们传递给主类

我已经尝试将单独的ActorGestureListener添加到ScrollPane但是根本没有得到任何事件

我的选项类实现了这些

public class OptionsScreen  implements Screen, GestureListener, InputProcessor

我使用多路复用器来获取手势和舞台ui事件

private InputMultiplexer inputMultiplexer = new InputMultiplexer(this);

inputMultiplexer.addProcessor(stage);
inputMultiplexer.addProcessor(new GestureDetector(this));
Gdx.input.setInputProcessor(inputMultiplexer);

ScrollPane是这样构建的,包括不起作用的ActorGestureListener

ScrollPane scrollPane = new ScrollPane(table, skin);
        scrollPane.setScrollingDisabled(false, true);

        scrollPane.addListener(new ActorGestureListener() 
        {
            @Override
            public void fling (InputEvent event, float velocityX, float velocityY, int button)
            {
                System.out.println("Fling event on scrollpane");
                OptionsScreen.this.fling(velocityX, velocityY, button);
            }
        });
scrollPane.pack();
        scrollPane.setHeight(Gdx.graphics.getHeight() - 10);
        scrollPane.setWidth(Gdx.graphics.getWidth() - 10);
        scrollPane.setCenterPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
        stage.addActor(scrollPane); 

这就是生成ScrollPane,我需要它在需要的时候滚动它,但是我的选项中的fling事件永远不会被调用,而且我已经添加了ScrollPane监听器

来自GestureDetector的OptionsScreen类fling侦听器

public boolean fling(float velocityX, float velocityY, int button) 
    {
        System.out.println("Fling "+velocityX);
        if(velocityX <= -Utils.getInstance().minVelocityToSwipe() ||
           velocityX >= Utils.getInstance().minVelocityToSwipe())
        {
game.SwapToScreen(new MainMenuScreen(game));
            return true;
        }
        return false;

有没有人有任何想法为什么在OptionsScreen级别或ScrollPane fling上的fling事件都没有被调用?

这是一个LibGdx错误。

我已经尝试将滚动设置为禁用并为两个轴启用它没有改变任何内容

是否有一个其他侦听器必须被覆盖并传递false而不是true?

感谢您的帮助:)

0 个答案:

没有答案