机器人游戏循环,如何控制速度和帧频 [英] Android game loop, how to control speed and frame rate

查看:136
本文介绍了机器人游戏循环,如何控制速度和帧频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个游戏为Android,我已经在开发手机1.它完美地进行了测试,速度恰到好处。不过,我敢肯定,手机的CPU越来越快。它们可能已经比dev的电话更快。

I've written a game for Android, and I've tested it on the Dev Phone 1. It works perfectly, the speed is just right. However, I'm sure phone CPU's are getting faster. They may already be faster than the dev phone.

我如何确保我的比赛在完全相同的速度运行,无论什么设备或如何快速运行?你知道有什么方法?如果我每次检查某种计时器在循环的顶部?

How do I make sure that my game runs at the exact same speed no matter what the device or how fast it runs? Do you know of any techniques? Should I check some kind of timer at the top of the loop each time?

我想我指的是帧速率 - 但主要的速度通过​​主游戏循环我的游戏运行

I guess I'm referring to frame rate - but mostly the speed at which my game runs through the main game loop.

任何理论或经验将是巨大的!谢谢你。

Any theory or experience would be great! Thank you.

推荐答案

如果你是针对特定的帧速率,其基本思想是,你应该有一个以期望的间隔执行你的游戏的刻度方法定时器或线程。随着计时器的实施是pretty的简单:只需设定一个计时器定期执行。当使用线程,你必须把线程连续刻度之间睡觉,如果它的运行速度比所需的帧速率。

If you are targeting certain frame rate, the basic idea is that you should have a timer or thread that executes your game's tick method at desired intervals. With timers the implementation is pretty trivial: just schedule a timer to execute at regular intervals. When using threads you have to put the thread to sleep between consecutive ticks if it runs faster than the desired frame rate.

然而,这本身并不能导致最佳结果作为间隔可以变化帧之间的比特。目前在这个问题上一个非常不错的一篇文章:<一个href="http://gafferongames.com/game-physics/fix-your-timestep/">http://gafferongames.com/game-physics/fix-your-timestep/.

However, this alone doesn't lead to the best possible results as the interval can vary a bit between the frames. There is a very good article on this issue: http://gafferongames.com/game-physics/fix-your-timestep/.

此外,目前已经有慢,快的Andr​​oid手机比开发手机1.所以,你必须prepare对于这两种情况下,如果你是针对所有的Andr​​oid设备。如果你的游戏是不是CPU沉重的,它可能是,你可以实现对所有设备所需的帧速率。但是,如果你不限制帧速率,你的游戏将是太快对Android手机的速度更快。

Also, there are already slower and faster Android phones than the dev phone 1. So you have to prepare for the both cases if you are targeting all Android devices. If your game is not that CPU heavy, it might be that you can achieve the desired frame rate on all the devices. But if you don't limit the frame rate, your game will be too fast on the faster Android phones.

这篇关于机器人游戏循环,如何控制速度和帧频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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