没有使用TextButton调用Libgdx InputListener"exit()"

Sie*_*rox 3 java android input listener libgdx

我想在InputListener中使用exit()方法来查看光标是否在按钮内.

以下是libGDX文档中的解释.

public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
Run Code Online (Sandbox Code Playgroud)

每当鼠标光标或手指触摸移出演员时调用.

但是当我将光标放在按钮上然后将其移到按钮外时,不会调用该方法.我正在测试它System.out.println("exited");,我在控制台中什么都没得到.

编辑:

LibGDX版本:最新稳定的夜莺

InputListener实现:

//This button class is a custom class to make button creation easier. This is the constructor.
public Button(Vector2 position, String packLocation, String text, Stage stage, BitmapFont font, Color color) {

//Removed buttonStyle creation etc. to shorten the code.
    button = new TextButton(text, buttonStyle);
    button.setPosition(position.x, position.y);
    stage.addActor(button);
    Gdx.input.setInputProcessor(stage);
    pressed = false;

    button.addListener(new ClickListener() {

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

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            pressed = false;
        }

        @Override
        public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
            System.out.println("exited");
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

编辑:

将鼠标悬停在按钮上也不会改变按钮的纹理,因为我将其设置为如此:

buttonStyle.over = skin.getDrawable("over");

但点击确实.

Sie*_*rox 6

搜索了几个小时后,我终于找到了遗漏的东西.stage.act();必须在render方法中调用.当我们将鼠标悬停在按钮上以及InputListener中的enter/exit方法时,这两者都为纹理更改提供了功能.