move saving flxsprite to png to SpriteTools
This commit is contained in:
@@ -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
|
||||
|
@@ -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))))
|
Reference in New Issue
Block a user