java - 未使用 TextButton 调用 Libgdx InputListener "exit()"

标签 java android input libgdx listener

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

这是 libGDX 文档中的解释。

public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)

Called any time the mouse cursor or a finger touch is moved out of an actor.

但是当我将光标放在按钮上然后将其移到按钮外时,不会调用该方法。我正在通过 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");
        }
    });
}

编辑:

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

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

但是点击会。

最佳答案

经过几个小时的搜索,我终于找到了丢失的东西。 stage.act(); 必须在 render 方法中调用。当我们将鼠标悬停在按钮上时,这既为纹理更改提供了功能,也为 InputListener 中的进入/退出方法提供了功能。

关于java - 未使用 TextButton 调用 Libgdx InputListener "exit()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24788443/

相关文章:

java - 在 Mac 上使用 Netbeans 连接 SQLite

java - Visio转SVG转换器

java - 不同API级别上View元素的不同外观-Android

java - 使用 jdbc 执行 sql 文件并将日志写入文件而不是 std 输出或仅打印错误

c++ - 我无法让非常基本的命令提示 rune 本处理器正常工作。 ofstream() 的问题

android - 每行中具有动态列数的 GridView

android - 下载应用程序时,Google Play 是否包含所有 mipmap 密度?

android - 为什么 commonsware 使用 ActionBarSherlock 而不是本地库?

css - 为什么 input[type=text] 在 IE 中不起作用

javascript - 检测 VSCode activeTextEditor 的文本输入