android - Resize libgdx correctly after orientation changed -
i have square images on stage. reason become rectangles after resize. how resize them correctly? , how manually resize game?
as see have 230x230, can't rectangles
imagesendpos[i] = new image(skin1, "square"); imagesendpos[i].setwidth(230); imagesendpos[i].setheight(230); imagesendpos[i].setposition(pointiend.getx(), pointiend.gety()); stage.addactor(imagesendpos[i]);
create() method
public void create() { stage = new stage(); gdx.input.setinputprocessor(stage); soundcontainter=new soundcontainter(); soundcontainter.init(tasksheet,audios); camera = new orthographiccamera(gdx.graphics.getwidth(), gdx.graphics.getheight()); camera.settoortho(true, gdx.graphics.getwidth(), gdx.graphics.getheight()); camera.update(); }
resize() method
public void resize(int width, int height) { stage.getviewport().setscreensize(width, height); camera = new orthographiccamera(gdx.graphics.getwidth(), gdx.graphics.getheight()); camera.settoortho(true, gdx.graphics.getwidth(), gdx.graphics.getheight()); if(width<height) { float w=camera.viewportwidth; float h=camera.viewportheight; camera.viewportwidth = h; camera.viewportheight = w; }else{ camera.viewportwidth = width; camera.viewportheight = height; } camera.update(); }
render()
public void render() { gdx.gl.glclear(gl20.gl_color_buffer_bit); stage.getbatch().setprojectionmatrix(camera.combined); stage.act(gdx.graphics.getdeltatime()); stage.draw(); }
because cramming picture. when changes orientation sure switch camera.viewportwidth camera.viewportheight
Comments
Post a Comment