libgdx屏幕适配分析

libgdx有个虚拟分辨率的概念,我们在初始化Stage时,可以传入我们
定义的虚拟分辨率,
new Stage(new ScalingViewport(Scaling.stretch, 480, 800, new OrthographicCamera()));
Scaling.stretch 这个是你的适配策略,适配策略可以选择下面的这些:


<pre name="code" class="java"> /** Scales the source to fit the target while keeping the same aspect ratio. This may cause the source to be smaller than the
* target in one direction. */
fit,
/** Scales the source to fill the target while keeping the same aspect ratio. This may cause the source to be larger than the
* target in one direction. */
fill,

//fillX这个适配策略是:宽度即X方向,缩放到和屏幕一样大小,即fill the target in the x direction,而且高度即Y方向
//上根据X方向的缩放比进行缩放(keeping the same aspect ratio),这样图形就不会变形,以为X,Y方向上的缩放比相同,
//当时会出现一个问题,就是Y方向上可能出现黑边,也可能超出显示屏幕。这种对宽度要求固定的可以使用。对高度做些处理。
//比如我们根据宽度的缩放比,计算出虚拟高度,然后把我们的图片根据这个虚拟高度摆放。
/** Scales the source to fill the target in the x direction while keeping the same aspect ratio. This may cause the source to be
* smaller or larger than the target in the y direction. */
fillX,
/** Scales the source to fill the target in the y direction while keeping the same aspect ratio. This may cause the source to be
* smaller or larger than the target in the x direction. */
fillY,

//stretch长和宽都完全缩放到和屏幕一样大小,这样可能产生变形,如720*1280的屏幕,高度方向的缩放比1208/800 = 1.6
//宽度方向的缩放比720/480 = 1.5,那么,因为长度和宽度方向的缩放比不同,就会到时我们的图片显示到
//屏幕上时,出现变形拉伸。
/** Scales the source to fill the target. This may cause the source to not keep the same aspect ratio. */
stretch,
/** Scales the source to fill the target in the x direction, without changing the y direction. This may cause the source to not
* keep the same aspect ratio. */
stretchX,
/** Scales the source to fill the target in the y direction, without changing the x direction. This may cause the source to not
* keep the same aspect ratio. */
stretchY,
/** The source is not scaled. */
none;


480,800是虚拟分辨率,我们做图片时,就按照这个
尺寸作图就可以了,而且我们做界面,排布局时,也根据这个大小,放置我们的UI元素,显示到屏幕上时,会根据我们的适配策略进行缩放,
然后显示到屏幕上。
[url]http://www.mamicode.com/info-detail-566357.html[/url]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值