java - Libgdx: Why is my button not showing up -
i trying make button show no avail. have been following following tutorial online here. in tutorial button shows after splash screen. in code doesnt show @ all. here code button.
import com.badlogic.gdx.gdx; import com.badlogic.gdx.screen; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.g2d.bitmapfont; import com.badlogic.gdx.graphics.g2d.textureatlas; import com.badlogic.gdx.scenes.scene2d.stage; import com.badlogic.gdx.scenes.scene2d.ui.skin; import com.badlogic.gdx.scenes.scene2d.ui.table; import com.badlogic.gdx.scenes.scene2d.ui.textbutton; import com.badlogic.gdx.scenes.scene2d.ui.textbutton.textbuttonstyle; public class mainmenu implements screen{ private stage stage; private textureatlas atlas; private skin skin; private table table; private textbutton buttonstart; private bitmapfont black; @override public void show() { stage = new stage(); atlas = new textureatlas("buttons/buttons.pack"); skin = new skin(atlas); table = new table(skin); black = new bitmapfont(gdx.files.internal("fonts/black.fnt"), false); table.setbounds(0, 0, gdx.graphics.getwidth(), gdx.graphics.getheight()); textbuttonstyle textbuttonstyle = new textbuttonstyle(); textbuttonstyle.up = skin.getdrawable("play.up"); textbuttonstyle.down = skin.getdrawable("play"); textbuttonstyle.pressedoffsetx = 1; textbuttonstyle.pressedoffsety = -1; textbuttonstyle.font = black; buttonstart = new textbutton("play", textbuttonstyle); buttonstart.pad(20); table.add(buttonstart); table.debug(); stage.addactor(table); @override public void render(float delta) { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); stage.act(delta); stage.draw(); }
thank you
summary due discussion topic:
the problem not directly in mainmenu class (although there little issue described below).
as turned out there no mainmenu screen launch in project. main class (malawianculture) has been calling splash screen there no transition mainmenu.
changing
//malawianculture @override public void create() { setscreen(new splash()); }
to
//malawianculture @override public void create() { setscreen(new mainmenu()); }
"resolved" problem - of course necessary make proper transition splash mainmenu because desired flow of application.
there little problem mainmenu class , it's assets. there black.fnt file font lacking with
page id=0 file="black_0.tga" page id=1 file="black_1.tga"
image files (.tga image format). necessary add .tga files or comment creating font .fnt file make running.
//black = new bitmapfont(gdx.files.internal("black.fnt"), false); .... textbuttonstyle.font = new bitmapfont(); buttonstart = new textbutton("", textbuttonstyle); ...
Comments
Post a Comment