How To Get Screen Resolution Of An Android Device Using Libgdx?
I am working android game development and I am new in it. I want to develop a game which screen resolution free. It will be enough for me if i get to know that how to catch screen
Solution 1:
Gdx.graphics.getWidth();
Gdx.graphics.getHeight();
:)
Solution 2:
ok you can get the screen resolution by this
Gdx.graphics.getWidth();
//for screen width
Gdx.graphics.getHeight();
//for screen height
and if you want to make a screen resolution free game you can set the view port like this
float scrw=320;
float scrh=480;
scrw is viewport's width and scrh is viewport's height
and set the camera to
camera = newOrthographicCamera();
camera.setToOrtho(false, scrw, scrh);
camera.update();
Solution 3:
Though there are some answers here on my question. This is what exactly worked for me. I had to add 'app' after 'Gdx' for it to work.
Gdx.app.graphics.getWidth();
Gdx.app.graphics.getHeight();
Solution 4:
In the newer LibGDX release, the code is now
int width = Gdx.app.getGraphics().getWidth();
int height = Gdx.app.getGraphics().getHeight();
Solution 5:
int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
works for me.
Post a Comment for "How To Get Screen Resolution Of An Android Device Using Libgdx?"