textPlate helper

This commit is contained in:
2023-05-11 12:36:09 -06:00
parent 9d51d83e38
commit 76e0502faf

View File

@@ -58,4 +58,16 @@
(let [bitmapData sprite.pixels
&mut bytes (new ByteArray)]
(set bytes (bitmapData.encode bitmapData.rect (new PNGEncoderOptions true) bytes))
(File.saveBytes file bytes))))
(File.saveBytes file bytes))))
(function :FlxSprite textPlate [:String text :Int size :Int margin &opt :FlxColor textColor :FlxColor bgColor]
(unless textColor (set textColor FlxColor.WHITE))
(unless bgColor (set bgColor FlxColor.BLACK))
(let [flxText (new FlxText 0 0 0 text size)
textWidth flxText.width
textHeight flxText.height
plate (new FlxSprite)]
(set flxText.color textColor)
(plate.makeGraphic (+ (* 2 margin) textWidth) (+ (* 2 margin) textHeight) bgColor)
(plate.stamp flxText margin margin)
plate))