LibGdx的FPS过多.如何限制? [英] LibGdx too much FPS. How to limit?

查看:64
本文介绍了LibGdx的FPS过多.如何限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做游戏,但是在某些(奇怪的)低端android设备(Galaxy S mini,Galaxy ACE)上遇到了问题,但实际上硬件质量很差.FPS在85+以上的设备上以及在其他设备(HTC Desire,Sony Xperia Arc S,Samsung Galaxy S,HTC Wildfire)上都是FPS正常"(大约60FPS).计算机上也显示了60 FPS.显然85+ FPS太多了,因为游戏体验不同,并且可能会给那些使用85FPS +玩游戏的玩家带来不公平的优势.

I'm doing a game and I have a problem on some (strange) low end android devices (Galaxy S mini, Galaxy ACE ), with actually bad hardware. The FPS is on both devices 85+, and on other devices (HTC Desire, Sony Xperia Arc S, Samsung Galaxy S, HTC Wildfire ) the FPS is "normal" (around 60FPS). Also 60 FPS is showing on computer too. Obviously 85+ FPS is too much, because the game experience is different and it may cause unfair advantage to those players who are playing on 85FPS+.

我想将FPS限制为MAX 60.

I want to limit the FPS to MAX 60.

我已经搜索了这个论坛,并且找到了我现在正在询问的确切问题.使用Thread.sleep()限制Libgdx游戏中的FPS不会不起作用

I've already searched this forum and I've found the exact question I'm asking right now. Limit FPS in Libgdx game with Thread.sleep() doesn't work

@daniel用户的(接受的)解决方案是这样的:

The (accepted) solution from user @daniel was this:

Thread.sleep((long)(1000/30-Gdx.graphics.getDeltaTime()));

但是问题是这对我不起作用.如果我使用该代码(用30替换为60),则得到30-33 FPS;如果仅使用Daniel的代码,则得到15-17 FPS.为什么会这样,为什么对我不起作用?如何将所有设备上的FPS限制为MAX 60?我在计算机和设备上测试了此代码.

But the thing is that doesn't work for me. If I use that code (30 replaced with 60 ), I get 30-33 FPS or if I use just the Daniel's code I get around 15-17 FPS. Why is that , and why is not working for me ? How to limit FPS on all devices to MAX 60 ? I tested this code on computer, and on devices also.

高度重视任何帮助.谢谢.

Any help HIGHLY appriciated. Thank you.

推荐答案

在启动器类中;

AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.foregroundFPS = 60;
initialize(new MyGdxGame(), config);

我不知道这是一项新功能还是旧功能.在尝试使线程休眠之前使用它.

I don't know if this is a new feature or an old one. Use this before trying to sleep the thread.

我强烈建议不要通过休眠线程来限制帧,只是为了使所有设备快速或慢速地以相同的速度运动.使用类似的方法在屏幕上移动内容.

I highly recommend not limiting the frames by sleeping the thread, just to the keep the motion at the same pace for all the devices running fast or slow. Use something like this to move things on the screen.

x+= speed*Gdx.graphics.getDeltaTime();

祝您在使用libGDX的过程中一切顺利,看来您才刚刚开始.因为刚开始时我在问同样的问题:)

Good luck on your adventure with libGDX, it seems that you are just started. Because when I was just started I was asking the same questions :)

这是一个提示:

Here is a tip:

如果您的游戏中发生碰撞,并且用户通过拖动窗口等使游戏进入睡眠状态. Gdx.graphics.getDeltaTime()函数将返回意外高的值.例如,您期望的是2秒而不是16毫秒(60fps).在这种情况下,您的角色将跳过墙壁,并且碰撞检测将失败.因此,您可以执行以下操作:

If you have collision in your game, and if the user sleeps the game by dragging the window etc. Gdx.graphics.getDeltaTime() function will return an unexpectedly high value. For example 2 seconds instead of 16 milliseconds (60fps) you were expecting. And in that case your character will jump, through walls and collision detection will fail. So here is what you can do:

  1. 您可以覆盖该函数,并取最后10帧的平均值并返回该值(在某些情况下,它有一些缺陷,但在其他情况下,则更好).
  2. 如果该值超过30秒,则可以返回30毫秒.因此,角色不会跳开,而是穿过墙壁……即使玩家将其睡眠一个世纪也是如此.
  3. 将两者结合在一起.(最佳)取平均值时,计数值不要超过30毫秒.


我写了一个有关此主题的页面,该页面位于我的网站上的教程"部分.一探究竟. nightlybuilddigital.ga

这篇关于LibGdx的FPS过多.如何限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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