简体   繁体   English

libgdx用户关闭屏幕

[英]libgdx user switches off screen

I just noticed that when I turn off my screen on my mobile device and turn it on again some graphics resize or disappear. 我只是注意到,当我关闭移动设备上的屏幕并再次打开它时,某些图形会调整大小或消失。 My game is coded towards 800x480 resolution and my HTC Desire HD doesn't have this problem (it has a 800x480 resolution). 我的游戏编码为800x480分辨率,而我的HTC Desire HD没有这个问题(它具有800x480分辨率)。 However, when tested on my HTC One or a Samsung Galaxy S3 the graphics scale or behave weird. 但是,在我的HTC One或Samsung Galaxy S3上进行测试时,图形缩放或表现怪异。

The only thing those objects who behave weird have in common are that they rotate every frame. 那些行为怪异的对象唯一的共同之处在于它们每帧都会旋转一次。 Stationary objects don't seem to be affected at all. 固定物体似乎根本不受影响。

I have stars who rotates and scales up/down every frame and I have a moving block who goes left/right or up/down. 我有恒星,它们每帧旋转并按比例放大/缩小,而我有一个移动块,向左/向右或向上/向下移动。 The moving block seems to ignore collision when the screen is restarted and disappears to places he should not be able to reach. 重新启动屏幕时,移动的块似乎忽略了碰撞,并消失到了他本人无法到达的位置。

Any ideas? 有任何想法吗?

Thanks in advance. 提前致谢。

When you turn off the screen, rendering is paused (ie no calls to render() are made). 当您关闭屏幕时,渲染将暂停(即,不会调用render() )。 When you resume, Gdx.graphics.getDeltaTime() will be very large as the last frame was rendered at least some seconds ago. 当您继续时, Gdx.graphics.getDeltaTime()将非常大,因为至少在几秒钟前呈现了最后一帧。 So the delta time values that are normally in the order of 0.0166 (60 FPS) will now be in the order of a 100 times greater. 因此,通常为0.0166 (60 FPS)量级的增量时间值现在将大100倍。

If you are using this delta to take a physics simulation / collision check step, that will go beserk because it's way too large. 如果您使用此增量进行物理模拟/碰撞检查步骤,则该过程会发疯,因为它太大了。 Rotation shouldn't be a real problem, but scaling will also go out the roof. 旋转不应该是一个真正的问题,但是缩放也会逐渐消失。

A simple way to avoid this is to put in something like 避免这种情况的一种简单方法是放入类似

if (delta > 0.1f)
    delta = 0.0166f

to avoid taking really large steps. 避免采取非常大的步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM