Created
April 10, 2019 15:22
-
-
Save thejustinwalsh/4060de15e0bd98ecbb66d0eadeb3b9b1 to your computer and use it in GitHub Desktop.
Heaps Debug Info UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace
hxd.Res.fonts.tinyunicode12.toFont();
with font of choice.