Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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) { = game;

    stage = new Stage(,,

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

    world = new World(new Vector2(0.0f, 0.0f), false);
    // camera = new OrthographicCamera( / 10.0f,
    // / 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 =;


    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.

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

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.

share|improve this answer
Do you mean images with a size that is a power of 2, e.g. 128, 256, 512 pixels wide and so on? – doppelgreener Apr 25 '12 at 11:39
Also don't forget to accept this answer as correct when you can in 24 hours. :) – doppelgreener Apr 25 '12 at 11:39
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); – 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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