java - Need help in using scene2d button in libgdx -
java - Need help in using scene2d button in libgdx -
i new libgdx. trying create custom button extending com.badlogic.gdx.scenes.scene2d.ui.button.
i want button related logic in class. not getting how create click work. read many tutorials regarding adding event listeners nil working.
public class restartbutton extends button { public restartbutton(buttonstyle style) { super(style); } @override public void draw(spritebatch batch, float parentalpha) { batch.draw(textureprovider.getinstance().getrestart(), 175, 100); }
}
and trying add together button in screen(i.e in show method) this
restartbutton restartbutton; restartbutton=new restartbutton(new buttonstyle()); stage stage; stage.addactor(restartbutton);
i able see button on screen. want add together code gets invoked when button clicked or touched. can please help ?
it not work because need setbounds button. if wanted draw button in position (175, 100) create button straight button class , call
button.setbounds(x, y, width, height);
then adding listener work because button have position , area in stage. if still need extend button class own reasons, can set bounds in extended class ditectly or can pass argument in restartbutton class. similar to:
public restartbutton(buttonstyle style, vector2 position, vector2 size) { super(style); this.setbounds(position.x, position.y, size.x, size.y); }
then button automatically drawn position want without need of overriding draw method. add together listener using this.addlistener(yourlistener);
hope helps.
java android button libgdx scene2d
Comments
Post a Comment