java - Libgdx Texture Size Android -


i'm having problem scaling images ,every device has different screen resolution , can't figure out how scale them down in libgdx platform, example today i've made small game android , problem facing is.. enter image description here

offcurse can scale them down ,but not right way, because if has tablet butttons fit perfect,and in libgdx far know cant use layouts sw600dp,large,xlarge etc ...how can scale them depend of screen width , height

stage = new stage();     gdx.input.setinputprocessor(stage);     font = new bitmapfont();     skin = new skin();     buttonatlas = new textureatlas(gdx.files.internal("data/spritesheetbuttons.pack"));     skin.addregions(buttonatlas);     table table = new table();     table.setbounds(0,0,buttonatlas.getregions().get(0).getregionwidth()*2 , buttonatlas.getregions().get(0).getregionheight());      textbuttonstyle = new textbuttonstyle();     textbuttonstyle.font = font;     textbuttonstyle.up = skin.getdrawable("left");     textbuttonstyle.down = skin.getdrawable("left");     textbuttonstyle.checked = skin.getdrawable("left");     buttonleft = new textbutton("button1", textbuttonstyle);     table.add(buttonleft);      textbuttonstyle = new textbuttonstyle();     textbuttonstyle.font = font;     textbuttonstyle.up = skin.getdrawable("right");     textbuttonstyle.down = skin.getdrawable("right");     textbuttonstyle.checked = skin.getdrawable("right");     buttonright = new textbutton("button1", textbuttonstyle);     table.add(buttonright);     stage.addactor(table);        table = new table();     table.setbounds(game.screen_width-buttonatlas.getregions().get(0).getregionwidth(),0,buttonatlas.getregions().get(0).getregionwidth() , buttonatlas.getregions().get(0).getregionheight()*2);      textbuttonstyle = new textbuttonstyle();     textbuttonstyle.font = font;     textbuttonstyle.up = skin.getdrawable("up");     textbuttonstyle.down = skin.getdrawable("up");     textbuttonstyle.checked = skin.getdrawable("up");     buttonup = new textbutton("button1", textbuttonstyle);     table.add(buttonup);     table.row();      textbuttonstyle = new textbuttonstyle();     textbuttonstyle.font = font;     textbuttonstyle.up = skin.getdrawable("down");     textbuttonstyle.down = skin.getdrawable("down");     textbuttonstyle.checked = skin.getdrawable("down");     buttondown = new textbutton("button1", textbuttonstyle);     table.add(buttondown);     stage.addactor(table);       buttonright.addlistener(new eventlistener() {          @override         public boolean handle(event event) {          }     });     buttonleft.addlistener(new eventlistener() {          @override         public boolean handle(event event) {          }     });     buttondown.addlistener(new eventlistener() {      @override     public boolean handle(event event) {         // todo auto-generated method stub         return false;     }     });     buttonup.addlistener(new eventlistener() {      @override     public boolean handle(event event) {         // todo auto-generated method stub         return false;     }     }); 

it looks you're relying on asset size , using imaginary pixel units. have @ this post why shouldn't that. instead use a viewport more meaningful units. e.g. use actual size of screen (e.g. in inches or centimeters) viewport , specify size of button (again in inches or centimeters) want them be. might want/need call drawable#setminwidth(), depending on skin.

float widthinches = (float)gdx.graphics.getwidth() * gdx.graphics.getppix(); float heightinches = (float)gdx.graphics.getheight() * gdx.graphics.getppiy(); stage = new stage(new stretchviewport(widthinches, heightinches)); ... // e.g. if want buttons 1 1 inch  button.setsize(1f, 1f); button.getstyle().up.setminwidth(1f); button.getstyle().up.setminheight(1f); ... etc. other drawables button uses 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -