user interface - Libgdx, stage is creating duplicate widgets when run on android -
i trying display textfield on screen. works when desktop version run when run android version textfield duplicated , background messed up.
code of screen class:
public class setupscreen implements screen { private stage stage; private table table; private textfield paymentfield; @override public void show() { stage = new stage(); gdx.input.setinputprocessor(stage); table = new table(); table.setfillparent(true); stage.addactor(table); pixmap bgpixmap = new pixmap(1, 1, format.rgba8888); bgpixmap.setcolor(color.gray); bgpixmap.fill(); texture bgtexture = new texture(bgpixmap); pixmap cursorpixmap = new pixmap(1, 1, format.rgba8888); cursorpixmap.setcolor(color.white); cursorpixmap.fill(); texture cursortexture = new texture(cursorpixmap); pixmap selpixmap = new pixmap(1, 1, format.rgba8888); selpixmap.setcolor(color.blue); selpixmap.fill(); texture seltexture = new texture(selpixmap); textfieldstyle textfieldstyle = new textfieldstyle(); textfieldstyle.background = new spritedrawable(new sprite(bgtexture)); textfieldstyle.cursor = new spritedrawable(new sprite(cursortexture)); textfieldstyle.selection = new spritedrawable(new sprite(seltexture)); textfieldstyle.font = new bitmapfont(); textfieldstyle.fontcolor = color.white; paymentfield = new textfield("", textfieldstyle); paymentfield.setmessagetext("pay rate"); table.add(paymentfield); } @override public void render(float delta) { stage.act(delta); stage.draw(); } @override public void resize(int width, int height) { stage.getviewport().update(width, height); } @override public void pause() { } @override public void resume() { } @override public void hide() { } @override public void dispose() { stage.dispose(); } }
your screen messed because not clear screen @ beginning of each frame.
@override public void render(float delta) { gdx.gl.glclearcolor(0.0f, 0.0f, 0.0f, 0.0f); gdx.gl.glclear(gl20.gl_color_buffer_bit | gl20.gl_depth_buffer_bit); stage.act(delta); stage.draw(); }
another thing note ui should center camera. otherwise bottom-left corner of ui in middle of screen.
you last parameter of viewport.update()
method.
@override public void resize(int width, int height) { stage.getviewport().update(width, height, true); }
Comments
Post a Comment