java - libGDX orthographic camera view size (with Box2D) -


i have next easy class 1 ball , 4 walls around screen:

spritebatch batch; box2ddebugrenderer debugrenderer; world world; orthographiccamera camera;  public float virtual_width  = 720f; public float virtual_height = 1280f;  @override public void create () {      batch = new spritebatch();      camera = new orthographiccamera(virtual_width, virtual_height);     world = new world(new vector2(0, -9), true);      debugrenderer = new box2ddebugrenderer();      bodydef bodydef = new bodydef();     bodydef.type = bodydef.bodytype.dynamicbody;      circleshape circleshape = new circleshape();     circleshape.setradius(50);      fixturedef fixturedef = new fixturedef();     fixturedef.shape = circleshape;     fixturedef.restitution = 1;      body body = world.createbody(bodydef);     body.createfixture(fixturedef);      createwall(0f, -virtual_height/2, virtual_width/2, 30f);     createwall(0f, virtual_height/2, virtual_width/2, 30f);     createwall(-virtual_width/2, 0f, 30f, virtual_height/2);     createwall(virtual_width/2, 0f, 30f, virtual_height/2);  }  private void createwall(float x, float y, float hx, float hy){      bodydef bodydef = new bodydef();     bodydef.type = bodydef.bodytype.staticbody;     bodydef.position.set(x, y);      polygonshape polygonshape = new polygonshape();     polygonshape.setasbox(hx, hy);      fixturedef fixturedef = new fixturedef();     fixturedef.shape = polygonshape;      world.createbody(bodydef).createfixture(fixturedef);  }  @override public void render () {      camera.update();      gdx.gl.glclear(gl20.gl_color_buffer_bit);      world.step(1 / 60.0f, 8, 3);     batch.setprojectionmatrix(camera.combined);      batch.begin();     debugrenderer.render(world, camera.combined);     batch.end();  } 

and it's next screen on device (maybe not perfect screenshot):

enter image description here

the screen shifted left, it's because rounding errors?

update:

enter image description here

instead of this

public float virtual_width  = 720f; public float virtual_height = 1280f; 

try

public float virtual_width  = gdx.graphics.getwidth(); public float virtual_height =  gdx.graphics.getheight(); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -