public class Main extends ApplicationAdapter {
SpriteBatch batch;
OrthographicCamera camera;
Stage stage;
Image greyback;
Image circle;
private float width;
private float height;
@Override
public void create () {
batch = new SpriteBatch();
camera = new OrthographicCamera();
stage = new Stage();
Gdx.input.setInputProcessor(stage);
greyback = new Image(new Texture("greyback.png"));
circle = new Image(new Texture("circle.png"));
width = Gdx.graphics.getWidth();
height = Gdx.graphics.getHeight();
greyback.setWidth(width);
greyback.setHeight(height);
circle.setPosition(200,200);
circle.setBounds(200, 200, circle.getWidth(), circle.getHeight());
circle.setTouchable(Touchable.enabled);
circle.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("CLICKED");
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("REMOVED");
}
});
stage.addActor(greyback);
stage.addActor(circle);
}
@Override
public void render () {
stage.draw();
}
} But, when I click on the circle the touchlistener doesnt fire, why?
System.out.println()
only works on desktop. You can useGdx.app.log()
to make sure that it goes to the appropriate output regardless of platform \$\endgroup\$