LibGDX - 如何制作可触摸的图像?

时间:2014-03-23 09:13:21

标签: events click touch libgdx

所以我在LibGDX中开发了一款Android游戏,我偶然发现了一个问题:我有一个带有图像的场景,我希望能够点击/触摸图像并制作这样做之后发生的事情。 在过去的一天里,我一直试图谷歌解决方案,但我一直在错过重要的事情。这是我的代码:

public class ScreenSplash implements Screen {

    private Texture textureGlobe = new Texture(Gdx.files.internal("graphics/splash.png"));
    private Image imageGlobe = new Image((new TextureRegion(textureGlobe)));

    public ScreenSplash() {

        imageGlobe.addListener(new InputListener() {
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                Gdx.app.log(Game.LOG, "image clicked");
                return true;
            }
        });
        stageGame.addActor(imageGlobe);
    }

    ...

}

我也听说过我应该把它放在某个地方:

Gdx.input.setInputProcessor(inputProcessor);

但我真的不知道如何处理它。

2 个答案:

答案 0 :(得分:0)

您的Stage就是InputProcessor,所以请执行Gdx.input.setInputProcessor(stageGame);之类的操作。 Stage会将事件路由到演员。

答案 1 :(得分:0)

啊,我已经发现了问题所在。

我导入了java.awt.event.InputEvent而不是com.badlogic.gdx.scenes.scene2d.InputEvent,因此没有正确覆盖touchDown函数。

相关问题