How to get screen resolution of an android device using LIBGDX?(如何使用 LIBGDX 获取 android 设备的屏幕分辨率?)
问题描述
我正在从事 android 游戏开发,我是新手.我想开发一款屏幕分辨率免费的游戏.如果我知道如何使用 libgdx 库捕获 android 设备的屏幕分辨率,这对我来说就足够了.经过一番谷歌搜索后,我在不同的网站上阅读了以下代码,但它不适用于 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 resolution of an android device using libgdx library. After some googling i read the following code on different sites, but it is not for libgdx.
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
height = displaymetrics.heightPixels;
width = displaymetrics.widthPixels;
除此之外,我还使用了以下网站上提供的技术,该技术使用OrthographicCamera"类来解决问题,但对我也不起作用.
Except this i also used technique given on the following website that used "OrthographicCamera" class for solving the problem, and didn't work for me either.
http://www.java-gaming.org/index.php?topic=25685.0
我如何获得屏幕分辨率或任何方式来调整我的游戏的屏幕分辨率.
How can i get the screen resolution or any way to adjust screen resolution for my game.
推荐答案
虽然这里有一些关于我的问题的答案.这正是对我有用的.我必须在Gdx"之后添加app"才能正常工作.
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();
这篇关于如何使用 LIBGDX 获取 android 设备的屏幕分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 LIBGDX 获取 android 设备的屏幕分辨率?


基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01