java - 将鼠标悬停在文本上不改变颜色 - libgdx

标签 java eclipse colors libgdx hover

当我将鼠标悬停在字体上时,我试图将字体的颜色更改为白色,以便用户可以清楚地单击该特定按钮以继续。 然而,我很困惑为什么它没有变成白色,而是保持原来的颜色。 我正在使用 Hiero 来获取我的字体。

if (hovertext1.contains(tp.x, tp.y)) {
        font5.setColor(Color.WHITE);
        if (Gdx.input.isTouched()) {
            game.setScreen(new ChooseLevel(game));
            dispose();
        }
} else {
        font5.setColor(Color.BLACK);
}

我只是很困惑为什么当我将其悬停时它没有改变颜色?

悬停文本是使用矩形创建的变量。

tp - 来自:

Vector3 tp = new Vector3();
@Override
public boolean mouseMoved(int screenX, int screenY) {
    // TODO Auto-generated method stub
    camera.unproject(tp.set(screenX, screenY, 0));
    return false;

我在这里确定了hovertext1;

hovertext1 = new Rectangle(330,255,125,50);

如果我要让它返回 true,我会在哪里做呢?

最佳答案

这不是对您问题的直接回答,但我认为使用 Scene2D 库对您的任务来说会很方便。只是为了表明我的意思 - 这是一个非常简单的示例,说明如何按照您的要求进行操作:

public class MyGdxGame extends ApplicationAdapter {

    Stage stage;

    public void create() {
        stage = new Stage();

        stage = new Stage();
        final Label label = new Label("TEST", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
        label.setColor(Color.BLACK);
        label.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getWidth() / 2);
        label.addListener(
                new InputListener() {
                    @Override
                    public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
                        label.setColor(Color.WHITE);
                    }

                    @Override
                    public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
                        label.setColor(Color.BLACK);
                    }
                }
        );
        stage.addActor(label);
        Gdx.input.setInputProcessor(stage);
    }

    public void render() {
        Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        float delta = Gdx.graphics.getDeltaTime();
        stage.act(delta);
        stage.draw();
    }

}

了解有关 Scene2D 的更多信息:https://github.com/libgdx/libgdx/wiki/Scene2d

关于java - 将鼠标悬停在文本上不改变颜色 - libgdx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48631548/

相关文章:

java - 如何从 aerospike 中获取所有记录?

eclipse - 当我在 Eclipse 中清理项目时会发生什么?

java - 一种在 Java 中给定 Color 对象获取相应的十六进制颜色代码的方法?

html - 在十六进制值中指定 RGB 颜色有什么好处?

javascript - Vue.Js,如何在 v-for 中使用动态颜色和类

java - Spring MVC JSON 使用错误

java - 在多台机器上运行调度程序

Java 泛型和数字

android - 启动 Android 模拟器失败

eclipse - 该项目包含另一个具有相同存档名称的依赖项