4

所以我有一个像这样的 sceneu2.ui 表:

+--------------------------------------+
|+---------+ +------------+ +---------+|
|| Table 1 | | ScrollPane | | Table 2 ||
|+---------+ +------------+ +---------+|
+--------------------------------------+
|                             My Actor |
+--------------------------------------+

里面scrollpane是另一个table。外壳也是一个tableTable 1Table 2并且table里面scrollpane有相同的行数。

My Actor是简单的图像按钮演员,也支持鼠标悬停。

问题是,My Actor一开始没有出现(但它的边界存在——通过表调试行检查)但是当我scrollpane(用鼠标)滚动一些东西时,它出现了 2 秒钟,然后开始消失。(预期的结果应该是一直出现)

我究竟做错了什么?


My Actor班级:

public class GameButton extends Actor {
    public static abstract class Listener {
        public abstract void onClick();
    }

    final Texture[] current;
    final Listener listener;
    boolean disabled;
    int state = 0;

    public GameButton(Texture[] current, final Listener listener) {
        this.current = current;
        setWidth(current[0].getWidth());
        setHeight(current[0].getHeight());

        this.listener = listener;
        disabled = false;

        this.addListener(new InputListener() {
            boolean just_up = false;

            @Override
            public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
                state = 2;
                return true;
            }

            @Override
            public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
                state = 0;
                if (hit(x, y, false) != null) {
                    just_up = true;
                    state = 1;
                    if (listener != null && !disabled)
                        listener.onClick();
                }
            }

            @Override
            public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) {
                if (state == 0)
                    state = 1;
            }

            @Override
            public void exit (InputEvent event, float x, float y, int pointer, Actor toActor) {
                if (!just_up)
                    state = 0;
                just_up = false;
            }
        });
    }

    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

    @Override
    public void draw(SpriteBatch batch, float _) {
        super.draw(batch, _);
        batch.draw(current[disabled ? 0 : state], getX(), getY(), getWidth(), getHeight());
    }
}

用于将其添加到表中的代码:

    btnBack = new GameButton(Assets.btnBack, 0, 0, new GameButton.Listener() {
        @Override
        public void onClick() {
            /* removed */
        }
    });
    add(btnBack).colspan(3).right().bottom().height(128);
4

3 回答 3

5

我意识到这个问题已经 2 岁了,但我也遇到了这个问题,所以我想我会发布我的解决方案。对我来说,这只是将滚动条淡入淡出设置为假的情况,使用

ScrollPane scroll = new ScrollPane();
scroll.setFadeScrollBars(false);
于 2015-06-27T19:03:27.537 回答
4

add to the draw method in the actor setColor(1,1,1,1)

@Override
    public void draw(SpriteBatch batch, float _) {
        batch.setColor(1,1,1,1);
        super.draw(batch, _);
        batch.draw(current[disabled ? 0 : state], getX(), getY(), getWidth(), getHeight());
    }
于 2013-11-13T04:53:25.687 回答
0

ScrollPane 的默认“空白”皮肤/行为会进行一些淡入和淡出。我不清楚为什么,但它也会导致屏幕上的其他东西褪色。我对背景图像也有同样的问题。我怀疑如果您为 ScrollPane 定义自己的皮肤,您会看到您的按钮出现。

于 2013-08-30T15:56:44.747 回答