帧率:我指的是显示变化的速率.即调用Ondraw()并重绘画布.
所有Android设备都有默认费率吗?由于此速率取决于设备的处理能力,如何在开始为该移动设备编程之前找出设备的帧速率?
这可能是这个问题的后续问题,我建议让重绘循环一次又一次地重复绘制可能有点过分.可能有一个API来找出设备显示的功能,但如果有我不知道它.当您编写自己的事件循环/线程函数时,您可以通过调用"绘制"方法的频率来控制帧速率.通常,我认为在大多数情况下,刷新率为30左右就可以了.如果您正在编写快速动作游戏,那么需要快速动画,那么您可能希望尽可能快地运行,fps越多,它就越平滑.
典型的事件循环(线程运行函数)可能如下所示:
// define the target fps
private static final int UPDATE_RATE = 30; // Frames per second (fps)
public void run() {
while(running) { // volatile flag, set somewhere else to shutdown
long beginTimeMillis, timeTakenMillis, timeLeftMillis;
// get the time before updates/draw
beginTimeMillis = System.currentTimeMillis();
// do the thread processing / draw
performUpdates(); // move things if required
draw(); // draw them on the screen
// get the time after processing and calculate the difference
timeTakenMillis = System.currentTimeMillis() - beginTimeMillis;
// check how long there is until we reach the desired refresh rate
timeLeftMillis = (1000L / UPDATE_RATE) - timeTakenMillis;
// set some kind of minimum to prevent spinning
if (timeLeftMillis < 5) {
timeLeftMillis = 5; // Set a minimum
}
// sleep until the end of the current frame
try {
TimeUnit.MILLISECONDS.sleep(timeLeftMillis);
} catch (InterruptedException ie) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以使用Android 提供的dumpsys 工具。要获取有关设备显示的信息,请执行以下命令:
adb shell dumpsys display
Run Code Online (Sandbox Code Playgroud)
有关设备帧速率的信息在属性“mPhys”中提供。
你会发现类似的东西:
mPhys=PhysicalDisplayInfo{1080x1920, 60.000004 fps, densitiy 3.0,
480.0x480.0 dpi, secure true}
Run Code Online (Sandbox Code Playgroud)
设备的帧速率在第二个字段中,在我的情况下是 60.000004 fps
| 归档时间: |
|
| 查看次数: |
21443 次 |
| 最近记录: |