java - touch isn't detecting on libgdx button -
i'm new libgdx , learning libgdx scene2d.
in menu screen constructor had created stage device's resolution , added stage input processor:
stage = new stage(800, 480, false); stage.getcamera().position.set(400, 240, 0); gdx.input.setinputprocessor(stage);
now, created button , added stage:
pbutton start = new pbutton(assets.btn, assets.btn_p, assets.font50, "start"); start.setposition(600, 400); start.addlistener(new actorgesturelistener() { @override public void touchup(inputevent event, float x, float y, int pointer, int button) { super.touchup(event, x, y, pointer, button); getgame().setscreen(new gamescreen1(getgame())); system.out.println("set game"); } }); stage.addactor(start);
where pbutton
extends button
class as:
public class pbutton extends button { private bitmapfont font; private string text; private float sizex; private float sizey; private float posx; private float posy; public pbutton(textureregion up, textureregion down, bitmapfont font, string text) { super(new textureregiondrawable(up), new textureregiondrawable(down)); this.font = font; this.text = text; this.sizex = up.getregionwidth(); this.sizey = down.getregionheight(); setsize(sizex, sizey); font.setscale(initiate.getm_ratio()); } @override public void draw(spritebatch batch, float parentalpha) { super.draw(batch, parentalpha); font.draw(batch, text, posx + sizex / 2 - font.getbounds(text).width / 2, posy + sizey / 2 + font.getbounds(text).height / 2); } @override public void setposition(float x, float y) { this.posx = x; this.posy = y; super.setposition(posx, posy); } }
but when click on button, doesn't input.
update: problem solved after deep debugging found stage.dispose() method of previous screen if not called anyway help
actually not act gesture
on button. it's click or touch not gesture. change clicklistener
and onclick action , should work. regards
Comments
Post a Comment