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:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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;
Texture.setEnforcePotImages(false);
stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
false);
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);
Gdx.input.setInputProcessor(stage);
preferences = new Preferences();
}
@Override
public void render(float deltaTime) {
GL10 gl = Gdx.graphics.getGL10();
camera.update();
camera.apply(gl);
gl.glClearColor(0f, 0f, 0f, 1f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glViewport(0, 0, (int) viewport.width, (int) viewport.height);
world.step(1 / 60f, 3, 3);
world.clearForces();
stage.act(deltaTime);
stage.setCamera(camera);
}
@Override
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.

