move saving flxsprite to png to SpriteTools

This commit is contained in:
2022-07-02 23:19:56 +00:00
parent eb9112906c
commit 1107a03972
2 changed files with 14 additions and 1 deletions

View File

@@ -6,6 +6,11 @@ import flixel.FlxSprite;
import flixel.util.FlxColor;
import flixel.text.FlxText;
import flixel.math.FlxPoint;
import flash.display.PNGEncoderOptions;
import flash.utils.ByteArray;
#if sys
import sys.io.File;
#end
enum RelativeCoordinate {
// Negative means to count back from the far edge

View File

@@ -50,4 +50,12 @@
(let [text (new FlxText 0 0 0 text size)]
(when color
(set text.color color))
(drawOnSprite text canvas pos)))))
(drawOnSprite text canvas pos)))))
// Source: https://gist.github.com/miltoncandelero/0c452f832fa924bfdd60fe9d507bc581
(#when sys
(function :Void saveToPNG [:FlxSprite sprite :String file]
(let [bitmapData sprite.pixels
&mut bytes (new ByteArray)]
(set bytes (bitmapData.encode bitmapData.rect (new PNGEncoderOptions true) bytes))
(File.saveBytes file bytes))))