如何使用 LIBGDX 获取 android 设备的屏幕分辨率? [英] How to get screen resolution of an android device using LIBGDX?

查看:21
本文介绍了如何使用 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 设备的屏幕分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆