简体   繁体   English

Xcode 6:iOS Swift。 如何获得游戏帧率(fps)?

[英]Xcode 6: iOS Swift. How to get in game frame rate (fps)?

In my current Swift project for iOS, I need to divide a variable by current FPS on the device I am running it on. 在我当前的iOS Swift项目中,我需要在运行该设备的设备上将其除以当前FPS。 In my case, the program is running on my iPad mini. 就我而言,该程序正在我的iPad mini上运行。 I don't see a function, or any capability to do this. 我没有看到执行此操作的功能或任何功能。 Any ideas? 有任何想法吗? Thanks in advance! 提前致谢!

There is however, in "GameViewController.swift" a line: 但是,“ GameViewController.swift”中有一行:

skView.showsFPS = true

But I cannot access this value. 但是我无法访问此值。

You can access the SKView frameInterval property in the didMoveToView:(SKView *)view method. 您可以在didMoveToView:(SKView *)view方法中访问SKView frameInterval属性。

If the value is 1 you are running a 60 FPS. 如果值为1,则您正在运行60 FPS。 If the value is 2 you are running at 30 FPS. 如果值为2,则您以30 FPS的速度运行。 Anything else, get out your calculator. 别的,拿出您的计算器。

You can read up more detail in the Apple SKView docs . 您可以在Apple SKView 文档中阅读更多详细信息。

You set the FPS in the GameViewController: 您在GameViewController中设置FPS:

skView.frameInterval = 2;

Convert an integer to a float: 将整数转换为浮点数:

int myInt = 10;
float myFloat = (float)myInt;

I never used iOS before, but on android I used something like this on the onDraw function: 我以前从未使用过iOS,但是在android上,我在onDraw函数上使用了类似的方法:

dt = currentTime - lastTime;
lastTime = currentTime;         
tempDt += dt;
fps += 1;
if (tempDt >= 1000) {
    Log.d("FPS", String.format("%d", fps));
    tempDt = 0;
    fps = 0;
}

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

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