舞台中的Actor中的LibGDX侦听器不起作用

时间:2014-02-28 10:58:45

标签: events input libgdx listener stage

即使已将Actor添加到舞台并且输入处理器已设置为舞台,输入侦听器也不会在Actor中触发。这可能是什么问题? 在GameScreen内部(扩展屏幕)类:

public GameScreen(Game game) {
   this.game = game;
   stage = new Stage(800, 480, true);
   number = new Number();
   stage.addActor(number);
}

public void show() {
   Gdx.input.setInputProcessor(stage);
}

public void render(float delta) {
   Gdx.gl.glClearColor(0, 0, 0, 1);
   Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
   stage.act(delta);
   stage.draw();
}

Number的构造函数:

public Number() {
        addListener(new InputListener() {
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                System.out.println("touch down");
                return true;
            }

            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                System.out.println("touch up");
            }

            public boolean mouseMoved(InputEvent event, float x, float y) {
                System.out.println("mouse moved");
                return true;
            }
        });
}

0 个答案:

没有答案