I just can not understand what could be the matter.
There is an actor:
public class Quard extends Actor { Sprite sprite; private static float x, y = 0; public Quard() { sprite = new Sprite(new Texture(Gdx.files.internal("quard.png"))); this.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer, int button) { x = screenX; y = screenY; Gdx.app.log("tag", "touchDown"); return true; } }); } @Override public void draw(Batch batch, float parentAlpha) { sprite.setPosition(x, y); sprite.draw(batch); }}
There is a calling screen, where a Stage and this actor are created in the show () method:
@Override public void show() { camera = new OrthographicCamera(); camera.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0); viewport = new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera); //Создаем первого Актера image = new Image(new NinePatch(new Texture(Gdx.files.internal("fon.png")))); image.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); //Создаем второго актера quard = new Quard(); stage = new Stage(viewport); stage.addActor(image); stage.addActor(quard); quard.setTouchable(Touchable.enabled); image.setTouchable(Touchable.enabled); Gdx.input.setInputProcessor(stage); }
The problem is that the touchDown method does not work. What is the problem? I can not figure it out. Google knows this problem, but it is solved (what I found) by adding setInputProcessor .
Ps. I tried to substitute the actually written InputProcessor - everything works fine.
quard.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());Thank you very much! - AndreyEKB