Skip to content

Instantly share code, notes, and snippets.

@thejustinwalsh
Created April 10, 2019 15:22
Show Gist options
  • Save thejustinwalsh/4060de15e0bd98ecbb66d0eadeb3b9b1 to your computer and use it in GitHub Desktop.
Save thejustinwalsh/4060de15e0bd98ecbb66d0eadeb3b9b1 to your computer and use it in GitHub Desktop.
Heaps Debug Info UI
class DebugInfo extends h2d.Object
{
var sampleRate:Int;
var fpsText:h2d.Text;
var drawCallText:h2d.Text;
public function new(sampleRate:Int, parent:Null<h2d.Object>)
{
super(parent);
this.sampleRate = sampleRate;
var font = hxd.Res.fonts.tinyunicode12.toFont();
fpsText = new h2d.Text(font, this);
drawCallText = new h2d.Text(font, this);
drawCallText.y = 10;
haxe.Timer.delay(update, 0);
}
private function update()
{
var engine = h3d.Engine.getCurrent();
var fps:Float = engine.fps;
var start = h3d.Vector.fromColor(0xFF0000, 1.0);
var end = h3d.Vector.fromColor(0x00FF00, 1.0);
// FPS
var fpsColor = new h3d.Vector(1.0, 1.0, 1.0, 1.0);
fpsColor.lerp(start, end, Math.min(60.0, fps)/60);
fpsText.textColor = fpsColor.toColor();
fpsText.text = "FPS: " + Math.round(fps);
// Draw Calls
drawCallText.text = "Draw Calls: " + engine.drawCalls;
// Always on top
parent.addChildAt(this, parent.numChildren + 1);
haxe.Timer.delay(update, sampleRate);
}
}
@thejustinwalsh
Copy link
Author

Replace hxd.Res.fonts.tinyunicode12.toFont(); with font of choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment