I have an application written with libGDX that does not run with a resolution of 800x480, whereas on devices with other resolutions (e.g. 480x320) it works perfectly. It also works perfectly as a desktop application with a resolution of 800x480.

In onCreate() method I only have this code:

protected void onCreate(Bundle savedInstanceState) {
        initialize(new BreakTheBall(), false);

So what do I have to do to have it work in a resolution of 800x480? I have to ask this question because my samsung galaxy sx2 display only blank screen at the time of game execution but emulator work perfectly. I also want to said that all the given demo application by libGDX could not run on the same device resolution.

Also I like to mention the base class of my project which specify about stage, camera and viewport declaration

protected BreakTheBall game;
protected Stage stage;
protected World world;
protected OrthographicCamera camera;
protected Preferences preferences;
protected ArrayList<Obstacles> boxArrayList;
protected ArrayList<BlastBall> blastBallArrayList;

private static final int VIRTUAL_WIDTH = 480;
private static final int VIRTUAL_HEIGHT = 320;
private static final float ASPECT_RATIO = (float) VIRTUAL_WIDTH
        / (float) VIRTUAL_HEIGHT;
private Rectangle viewport;

// protected Box2DDebugRenderer renderer;

public AbstractScreen(BreakTheBall game) {
    this.game = game;

    stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),

    Constant.setStageRatio(stage.width(), stage.height());

    world = new World(new Vector2(0.0f, 0.0f), false);
    // camera = new OrthographicCamera(Gdx.graphics.getWidth() / 10.0f,
    // Gdx.graphics.getHeight() / 10.0f);
    camera = new OrthographicCamera((float) VIRTUAL_WIDTH / 10.0f,
            (float) VIRTUAL_HEIGHT / 10.0f);

    // camera.position.scale(0.0f, 0.0f, 0.0f);

    // renderer = new Box2DDebugRenderer(true, false, false);

    preferences = new Preferences();

public void render(float deltaTime) {
    GL10 gl = Gdx.graphics.getGL10();


    gl.glClearColor(0f, 0f, 0f, 1f);

    gl.glViewport(0, 0, (int) viewport.width, (int) viewport.height);

    world.step(1 / 60f, 3, 3);


public void resize(int width, int height) {

    float aspectRatio = (float) width / (float) height;
    float scale = 1f;

    Vector2 crop = new Vector2(0f, 0f);

    if (aspectRatio > ASPECT_RATIO) {
        scale = (float) height / (float) VIRTUAL_HEIGHT;
        crop.x = (width - VIRTUAL_WIDTH * scale) / 2f;
    } else if (aspectRatio < ASPECT_RATIO) {
        scale = (float) width / (float) VIRTUAL_WIDTH;
        crop.y = (height - VIRTUAL_HEIGHT * scale) / 2f;
    } else {
        scale = (float) width / (float) VIRTUAL_WIDTH;

    float w = (float) VIRTUAL_WIDTH * scale;
    float h = (float) VIRTUAL_HEIGHT * scale;

    viewport = new Rectangle(crop.x, crop.y, w, h);


I think above specified code provide more guidance to community members so please help me to come out of this problem.

  • 1
    \$\begingroup\$ Have you tried attaching the GDXApp to a View inside your Activity layout? View gameView = initializeForView(application, useGL20); \$\endgroup\$ – Chuck D Apr 17 '12 at 5:38
  • \$\begingroup\$ Yes, sir after you told I tries that but does not get success. \$\endgroup\$ – Siddharth Apr 17 '12 at 6:19
  • \$\begingroup\$ Can you post the create method in BreakTheBall? Are you using Screens? In my GDXApp class, I have the following code screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); in my create() method. \$\endgroup\$ – Chuck D Apr 17 '12 at 6:46
  • \$\begingroup\$ This is my onCreate() method @Override public void create() { setScreen(new MenuScreen(this)); } Also sir I am using screen class \$\endgroup\$ – Siddharth Apr 17 '12 at 7:28
  • \$\begingroup\$ What about your Camera code? \$\endgroup\$ – Chuck D Apr 17 '12 at 19:00

Thank you for the community for giving response to me. I found the answer of my question after hard working towards it. The solution is that WVGA (800x480) screen resolution only support the 2nd power images with resolution. So other members also take care about that so they do not have to waste time in that.

|improve this answer|||||
  • \$\begingroup\$ Do you mean images with a size that is a power of 2, e.g. 128, 256, 512 pixels wide and so on? \$\endgroup\$ – doppelgreener Apr 25 '12 at 11:39
  • \$\begingroup\$ If that's true, you can get around this by using OpenGL ES 2.0 by specifying "true" in your LwjglApplication constructor, eg. new LwjglApplication(new BreakTheBallGame(), "libGDX", 800, 480, true); \$\endgroup\$ – ashes999 Apr 25 '12 at 12:08

Set your target version level higher at manifest. You are setting it too low and that cause app start as combatibility mode. This is just android behaviour nothing to do with libgdx.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.