In my current Swift project for iOS, I need to divide a variable by current FPS on the device I am running it on. In my case, the program is running on my 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:
skView.showsFPS = true
But I cannot access this value.
You can access the SKView frameInterval
property in the didMoveToView:(SKView *)view
method.
If the value is 1 you are running a 60 FPS. If the value is 2 you are running at 30 FPS. Anything else, get out your calculator.
You can read up more detail in the Apple SKView docs .
You set the FPS in the GameViewController:
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:
dt = currentTime - lastTime;
lastTime = currentTime;
tempDt += dt;
fps += 1;
if (tempDt >= 1000) {
Log.d("FPS", String.format("%d", fps));
tempDt = 0;
fps = 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.