Reputation: 1581
I have a very strange issue. I have an actor which is just a sprite image. And won't show up on a mouse click. But only in a constructor:
** WORKS **
public GameScreen(Game game) {
....
MyActor actor = new MyActor();
stage.addActor(actor)
}
** NOT WORKING **
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
MyActor actor = new MyActor();
stage.addActor(actor);
return false;
}
Literally copied from the constructor to the event handling code. And the texture/sprite no longer shows up. How's that possible? I can verify that the draw function is called in both cases. This is my render method:
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
stage.act(delta);
stage.draw();
stage.getBatch().setProjectionMatrix(camera.combined);
}
Upvotes: 0
Views: 36
Reputation: 1791
You didn't set your screen/stage as input listener (Gdx.input.setInputProcessor(stage)
).
Furthermore, your Screen is not the input listener, the Stage is. To react on events, you have to set listeners to Actors. If you want to react on all available events, extend the Stage and override its touchdown method.
Upvotes: 1