Я создал простой тест с событием touchDown()
для актера изображения. Событие работает на сцене, но не на актере. Вот код:
Я установил InputProcessor
в конструкторе родительского класса (AbstractScreen
).
Gdx.input.setInputProcessor(this.stage);
В подклассе:
private TextureAtlas atlas;
private Image boardImg;
public void show(){
super.show();
atlas = new TextureAtlas(Gdx.files.internal("data/packs/mainMenu.atlas"));
AtlasRegion board = atlas.findRegion("board");
boardImg = new Image(board);
boardImg.addListener(new InputListener(){
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
Gdx.app.log("aaaa", "down");
return true;
}
});
stage.addActor(boardImg);
stage.addListener(new InputListener() {
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("aaaa", "stage down");
return true;
}
});
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
boardImg.setPosition(stage.getWidth()/2 - boardImg.getWidth()/2, stage.getHeight()/4);
}
Тестирую и на десктопе и на андроиде (результаты одинаковые). Я получаю событие «сцена вниз», но не событие актера. Я пробовал и без сценического события.