首页 > 其他 > 详细

libgdx屏幕适配分析(1)

时间:2015-04-13 10:58:21      阅读:263      评论:0      收藏:0      [点我收藏+]
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元素,显示到屏幕上时,会根据我们的适配策略进行缩放,
然后显示到屏幕上。

libgdx屏幕适配分析(1)

原文:http://blog.csdn.net/tianxiawuzhei/article/details/45021999

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!