How to get screen resolution of an android device using LIBGDX?

别等时光非礼了梦想. 提交于 2019-12-03 04:50:22
Gdx.graphics.getWidth();
Gdx.graphics.getHeight();

:)

sandeep kundliya

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 = new OrthographicCamera();
camera.setToOrtho(false, scrw, scrh);
camera.update(); 

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();

In the newer LibGDX release, the code is now

int width = Gdx.app.getGraphics().getWidth();
int height = Gdx.app.getGraphics().getHeight();
int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();

works for me.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!