1

I'm using the box2D render to view my graphics (I have tried using textures, and I get exactly the same result) My render code is as follows:

public void render()
{

    long startTime = System.nanoTime();
    world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3);
    float updateTime = (System.nanoTime() - startTime) / 1000000000.0f;
    startTime = System.nanoTime();
    float renderTime = (System.nanoTime() - startTime) / 1000000000.0f;

    GL10 gl = Gdx.app.getGraphics().getGL10();
    camera.update();
    camera.apply(gl);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    batch.setProjectionMatrix(camera.combined);

    renderer.render(world, camera.combined);

    batch.begin();


    font.setScale(0.020f);
    font.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond() + ", update: " + updateTime + ", render: " + renderTime, 0,
        20);
    batch.end();


}

Which works absolutely fine on the desktop version and displays as it should. enter image description here

However when I launch it on my phone, I get this, which is not what I want:

enter image description here

As you can see its been squashed to only take up on the top part of the screen.

Is there a bug in libgdx or am I missing something?

Edit: Complete creation code:

Vector2 pouchPos = new Vector2(0, -12);
    slingshotListener = new SlingshotListener(pouchPos);

    batch = new SpriteBatch();
    camera = new OrthographicCamera(32, 48);
    Gdx.input.setInputProcessor(slingshotListener);

    font = new BitmapFont();
    renderer = new Box2DDebugRenderer();
    world = new World(new Vector2(0, -10), true);

    BodyDef bd = new BodyDef();
    ground = world.createBody(bd);

    EdgeShape shape = new EdgeShape();
    shape.set(new Vector2(-16, -20), new Vector2(16, -20));

    FixtureDef fd = new FixtureDef();
    fd.shape = shape;
    ground.createFixture(fd);

    shape.dispose();

    Misc.createLine(new Vector2(-3, -16), pouchPos, camera, world).setSensor(true);
    Misc.createLine(new Vector2(3, -16), pouchPos, camera, world).setSensor(true);

    pic = new Texture(Gdx.files.internal("pong/ball.png"));
Derek
  • 882
  • 1
  • 14
  • 36
  • How are you setting up your viewport and camera position? – Steve Blackwell Mar 22 '12 at 18:33
  • I think it's a difference in display resolution that's causing the two to appear differently. The answer to this question might help: http://stackoverflow.com/q/9198932/324625 even though your setup is a little different (it doesn't look like you're using the 2D scene graph in libgdx). The main point is that you need to center your viewport and position your camera. These should be done when handling `resize()`. – Steve Blackwell Mar 22 '12 at 22:44

1 Answers1

0

I put this in the AndroidManifest.xml and it seemed to fix the issue:

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />
Derek
  • 882
  • 1
  • 14
  • 36