Libgdx fitting game inside all resolutions -
ok, have read every possible google entry on subject, , still not sure path take. @ moment here setup:
static final float width = 800; static final float height = 600; @override public void resize(int width, int height) { camera = new orthographiccamera(width, height); camera.position.set(width / 2, height / 2, 0); glviewport = new rectangle(0, 0, gdx.graphics.getwidth(), gdx.graphics.getheight()); ... } public void render(float delta) { gl20 gl = gdx.graphics.getgl20(); gl.glclearcolor(1, 0, 0, 1); gl.glclear(gl10.gl_color_buffer_bit); gl.glviewport((int) glviewport.x, (int) glviewport.y, (int) glviewport.width, (int) glviewport.height); camera.update(); .... } this fine job stretching across screen has huge drawbacks. proportions not stretched. example when define sprite in 800x600 world stays same on 1280x720 screen. affects sprites placed @ specific locations because location 400px on 800x600 not same on 1280x720 screen. have specific regions if touched happens, solution , ones have found on internet not work either. lets not talk aspect ratio, because every time think head hurts.
there must logical way of doing libgdx many games have been released can not seem find work. on have suggestions on how go on handling this?
first have make object of spritebatch class draw things. after set position of camera..you must update it..add following line
camera.update(); after updating it's position.
next,the problem of scaling can solved adding
batcher.setprojectionmatrix(camera.combined); after gl.glclear(gl10.gl_color_buffer_bit);
this useful since game involves lot of calculations,specially when integrate physics(box2d) them. so,try have smaller camera 800/40,600/40 , calculations according camera.then batcher.setprojectionmatrix(camera.combined) handle scaling thing. make sure doing calculations according camera. here batcher object of spritebatch class. after this..now draw things..
batcher.begin()
//draw things...
batcher.end()
you can refer these links https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests/src/com/badlogic/gdx/tests
Comments
Post a Comment