allow font specification on writeOnSprite

This commit is contained in:
2023-06-14 08:34:53 -06:00
parent 3d0cc19386
commit 7381447087

View File

@@ -41,13 +41,15 @@
(stamp.origin.set oX oY))))
// TODO allow specifying size relative to canvas
(function :Void writeOnSprite [:String text :Int size :FlxSprite canvas :RelativePosition pos &opt :FlxColor color]
(function :Void writeOnSprite [:String text :Int size :FlxSprite canvas :RelativePosition pos &opt :FlxColor color :String fontPath]
(let [lines (text.split "\n")
&mut offsetY (/ (* size lines.length) -2)]
(doFor text lines
(set pos.offsetY offsetY)
(+= offsetY size)
(let [text (new FlxText 0 0 0 text size)]
(when fontPath
(text.setFormat fontPath size color))
(when color
(set text.color color))
(drawOnSprite text canvas pos)))))