I am making a simple gui in libgdx and run into this problem ; when you click on the button it's bounds (?) are wrong since if I click under it, the game registers it as a click.
On the other end, if I click it at the top it won't get the click. It seems like the bounds are a bit under the button. I tried to set manually but nothing.
Also i tried changing sizes.
Looked here : too this is almost the same but no answer..
tabl = new Table();
stage =new Stage();
tabl.setSize(stage.getWidth()/2, stage.getHeight()/2);
tabl.defaults().size(500, 40);
g = game;
Gdx.input.setInputProcessor(stage);
skin = new Skin();
TextureAtlas te = new TextureAtlas(Gdx.files.internal("uiskin.atlas"));
skin.addRegions(te);
skin.add("default-font", new BitmapFont());
skin.load(Gdx.files.internal("uiskin.json"));
Pixmap r = new Pixmap(100,100,Format.RGBA8888);
r.setColor(0xff0000ff);
r.fillRectangle(1, 1, 13, 13);
Texture s = new Texture(r);
SpriteDrawable s1 = new SpriteDrawable(new Sprite(s));
TextButton gam = new TextButton("new games",skin);
gam.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
// TODO Auto-generated method stub
//g.setScreen(null);
new Logger("e").setLevel(10);
return true;
}
});
/*super.getS*/
LabelStyle tt = new LabelStyle(new BitmapFont(), Color.BLUE);
Label l = new Label("d",tt);
tabl.add(gam);
tabl.setDebug(true);
stage.addActor(tabl);
table.setDebug(true)
is the button being drawn inside the correct cell? And doesgam.setDebug(true)
generates a debug rectangle exactly over the button? \$\endgroup\$stage.draw
andstage.act
in some update method without anything else going on there that could effect it? What if you initialize the stage like thisstage = new stage(new ScreenViewport())
. \$\endgroup\$