How to display the real frame rate in kha?
<p>I started experimenting with kha on haxe, and compiled a sample project for my aged iPad2.</p>

<p>Now I wonder how to display the actual framerate on screen.</p>

<p>As a starting point I found this repo:</p>

<p><a href="https://github.com/lewislepton/kha-tutorial-series/blob/master/007_fontText" rel="nofollow noreferrer">https://github.com/lewislepton/kha-tutorial-series/blob/master/007_fontText</a></p>

<p>It loads a font and displays some text on screen. It also sets the framerate to 60fps.</p>

<p>So now I just need to calulate the fps and display it via drawString.</p>

<p>But how to calculate it?</p>

<p><strong>EDIT:</strong></p>

<p>Thanks to @RobDangerous this seems to work:</p>

<pre><code>package;

import kha.Framebuffer;
import kha.Color;
import kha.Assets;
import kha.input.Surface;
import kha.Font;
import kha.Scheduler;
import Std;


class Project {

    public var font:Font;

    public var previousRealTime:Float;
    public var realTime:Float;

    public function new() {
        font             = Assets.fonts.OpenSans;

        previousRealTime = 0.0;
        realTime         = 0.0;

        Surface.get().notify(onTouchDown, onTouchUp, onTouchMove);
    }

    public function update():Void {
        previousRealTime = realTime;
        realTime = Scheduler.realTime();
    }

    public function render(framebuffer:Framebuffer):Void {
        var graphics = framebuffer.g2;
        graphics.begin();

        var fps = 1.0 / ( realTime - previousRealTime );
        graphics.font = font;
        graphics.fontSize = 32;
        graphics.color = Color.White;
        graphics.drawString(Std.string(fps), 10, 10);

        graphics.end();
    }

    // ...
}
</code></pre>