by
1
6
1,616
0
Top 1% !
Popular
Famous
Tagged
Specified
OpenSource

Published on:

FrameworklibGDX
LanguageJava
LanguageText
LicenseMIT_X11

Getting the screen size with libGDX

Along with some other screen analysis methods.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/2944989/Getting-the-screen-size-with-libGDX?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
import com.badlogic.gdx.Gdx; import java.lang.Math; public class ScreenDetails { // ... /** * * @return Total count of pixels (height * width). */ private double getResolution() { return Gdx.graphics.getHeight() * Gdx.graphics.getWidth(); } /** * * @return PPI (Pixels Per Inch). */ private float getDensity() { return Gdx.graphics.getPpiX(); } /** * * @return Horizontal pixel count, squared. */ private double getWidthSquared() { return Math.pow(Gdx.graphics.getWidth(), 2); } /** * * @return Vertical pixel count, squared. */ private double getHeightSquared() { return Math.pow(Gdx.graphics.getHeight(), 2); } /** * * @return Approximate screen size or size of app on screen (diameter in inches). */ private double getScreenSize() { return (Math.sqrt(getWidthSquared() + getHeightSquared()) / getDensity()); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus