Search code examples
swiftsprite-kitframe-rate

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. 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.


Solution

  • 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;
    }