Utility functions, inlined where possible
Static methods
staticFUL(str:String):String
Return string with first character uppercase'd, rest lowercase'd @return
Parameters:
str |
---|
staticapplyResize(resize_ratio:Float, resize_ratio_axis:Int, w:Float, h:Float, ?pt:FlxPoint):FlxPoint
staticbmpToCSVLayer(color_index:Int, bd:BitmapData):String
Converts a PNG file to a comma-separated string. pixels that match color_index are flagged others are ignored must be a PERFECT MATCH
Parameters:
color_index | The matching color index |
---|
Returns:
A comma-separated string containing the level data in a FlxTilemap-friendly format.
staticinlinecenter(fb1:FlxObject, fb2:FlxObject, centerX:Bool = true, centerY:Bool = true):Void
Center fb2 on fb1's center point
Parameters:
fb1 | a FlxObject (does not move) |
---|---|
fb2 | a FlxObject (center on fb1) |
centerX | center X axis? |
centerY | center Y axis? |
staticclearArray(array:Array<Dynamic>):Void
This will MURDER an array, removing all traces of both it and its contents
Parameters:
null | array |
---|
staticclearArraySoft(array:Array<Dynamic>):Void
This will remove an array structure, but will leave its contents untouched. This can lead to memory leaks! Only use this when you want an array gone but you still need the original elements and know what you're doing.
Parameters:
null | array |
---|
staticcompareStringVars(variable:String, otherValue:String, type:String, op:String = "=="):Bool
Pass in two variables as strings, and compare them using proper casting based on a desired type
Parameters:
variable | some variable as a string, say "1.0", "2354", "false", or "happydays" |
---|---|
otherValue | another variable |
type | "string","int","float", or "bool" |
op | "==","!=","<",">","<=",">=" |
Returns:
the value of the comparison
staticfont(str:String, style:String = "", extension:String = ".ttf"):String
Given something like "verdana", "bold", ".ttf", returns "assets/fonts/verdanab.ttf" @return
Parameters:
str | |
---|---|
style | |
extension |
staticinlinefontStr(str:String, style:String = ""):String
Given something like "verdana" and "bold" returns "assets/fonts/verdanab" @return
Parameters:
str | |
---|---|
style |
staticgfx(id:String, dir1:String = "", dir2:String = "", dir3:String = "", dir4:String = "", suppressError:Bool = false):String
staticinlinehex2rgb(hex:Int):Array<Int>
Parses hex pixel value into a 3-length array of [r,g,b] ints @return
Parameters:
hex |
---|
staticinlinehexChar2dec(hex_char:String):Int
Parses an individual hexadecimal string character to the equivalent decimal integer value
Parameters:
hex_char | hexadecimal character (1-length string) |
---|
Returns:
decimal value of hex_char
staticinlineintStr_to_arr(str:String):Array<Int>
Converts a comma and hyphen list string of numbers to an int array
Parameters:
str | input, ex: "1,2,3", "2-4", "1,2,3,5-10" |
---|
Returns:
int array, ex: [1,2,3], [2,3,4], [1,2,3,5,6,7,8,9,10]
staticinlineintStr_to_arrStr(str:String):Array<String>
Converts a comma and hyphen list string of numbers to a String array
Parameters:
str | input, ex: "1,2,3", "2-4", "1,2,3,5-10" |
---|
Returns:
int array, ex: [1,2,3], [2,3,4], [1,2,3,5,6,7,8,9,10]
staticinlineinterpolate(hex1:Int, hex2:Int, amt:Float):Int
Returns a color somewhere between the given two. @return
Parameters:
hex1 | A hexadecimal color |
---|---|
hex2 | A hexadecimal color |
amt | 0=100% hex1, 1=100% hex2, 0.5=50% of each |
staticloadImageScaleToHeight(src:String, Height:Float, Smooth:Bool = true, checkFlxBitmap:Bool = false):String
staticloadMonoScaledImage(src:String, Scale:Float, smooth:Bool = true, checkFlxBitmap:Bool = false, fixAlphaChannel:Bool = false):String
For grabbing a version of an image src and dynamically scaling (and caching) it as necessary
Parameters:
src | the asset key of the base image |
---|---|
Scale | the scale factor of the new image |
smooth | whether to apply smoothing or not |
checkFlxBitmap | whether to use the FlxG.bitmap.get cache instead of Assets.getBitmapData |
Returns:
the unique key of the scaled bitmap
staticloadScaledImage(src:String, W:Float, H:Float, smooth:Bool = true):String
For grabbing a resolution-specific version of an image src and dynamically scaling (and caching) it as necessary
Parameters:
src | the asset key of the base image |
---|---|
W | the final scaled width of the new image |
H | the final scaled height of the new image |
Returns:
the unique key of the scaled bitmap
staticinlinepadDigits(i:Int, d:Int, padChar:String = "0"):String
Return a numeric string with leading zeroes
Parameters:
i | any integer |
---|---|
d | how many digits |
padChar | what to pad with ("0") by default |
Returns:
i's value as a string padded with padChar, exactly d digits in length
staticinlineparseHex(str:String, cast32Bit:Bool = false, safe:Bool = false, default_color:Int = 0x000000):Int
Parses hex string to equivalent integer, with safety checks
Parameters:
hex_str | string in format 0xRRGGBB or 0xAARRGGBB |
---|---|
cast32Bit | add an alpha channel if none is given |
safe | don't throw errors, just return -1 |
default_color | what to return if safe is true and it fails |
Returns:
integer value
staticperc_to_float(str:String):Float
If a string is a number that ends with a % sign, it will return a normalized percent float (0-100% = 0.0-1.0)
Parameters:
str | a percentage value, such as "5%" or "236.214%" |
---|
Returns:
a normalized float, or NaN if not valid input
staticpointify(str:String):FlxPoint
Parses a point expressed as a string to a FlxPoint object. Must be two numbers separated by a "," or an "x" This function strips extraneous characters first, ie "(",")"," ","=",":" @return
Parameters:
str |
---|
staticinlinergb2hex(r:Int, g:Int, b:Int):Int
Returns the hex pixel value of 3 r, g, b ints @return
Parameters:
r | |
---|---|
g | |
b |
staticscaleAndStoreTileset(orig_id:String, scale:Float, OrigW:Int, OrigH:Int, TileW:Int = -1, TileH:Int = -1, Smooth:Bool = true):String
This scales an image that contains tiles, being super OCD about it, making sure each tile is properly scaled and put in the correct position, and returns the new asset key
Parameters:
orig_id | asset id |
---|---|
scale | the scale factor |
OrigW | original width of the tile |
OrigH | original height of the tile |
TileW | final width of the tile |
TileH | final height of the tile |
Smooth |
Returns:
the asset key
staticscaleTileBmp(orig_id:String, scale:Float, origW:Int, origH:Int, W:Int = -1, H:Int = -1, smooth:Bool = true):BitmapData
This scales an image that contains tiles, being super OCD about it, making sure each tile is properly scaled and put in the correct position @return
Parameters:
orig_id | asset id |
---|---|
scale | the scale factor |
origW | original width of the tile |
origH | original height of the tile |
W | final width of the tile |
H | final height of the tile |
smooth |
staticinlinesplitBitString(str:String):Array<Int>
Splits a binary string with endlines into a big long int array
staticxml(id:String, extension:String = "xml", getAccess:Bool = true, dir:String = "assets/xml/"):Dynamic
staticxml_bool(data:Xml, att:String, default_:Bool = false):Bool
Safety wrapper for reading a bool attribute from xml
Parameters:
data | the Xml object |
---|---|
att | the name of the attribute |
what | to return if the value doesn't exist |
Returns:
true if att is "true" (case-insensitive) or "1", otherwise false
staticxml_color(data:Xml, att:String, cast32Bit:Bool = true, ?defaultColor:FlxColor):Null<FlxColor>
Safety wrapper for reading a FlxColor attribute from xml
Parameters:
data | the Xml object |
---|---|
att | a color string in either 0xRRGGBB or 0xAARRGGBB format |
cast32Bit | if true adds an alpha channel if not detected |
staticxml_f(data:Xml, att:String, default_:Float = 0):Float
Safety wrapper for reading a float attribute from xml
Parameters:
data | the Xml object |
---|---|
att | the name of the attribute |
default_ | what to return if the value doesn't exist |
Returns:
the attribute as a float if it exists, otherwise returns default
staticxml_i(data:Xml, att:String, default_:Int = 0):Int
Safety wrapper for reading an int attribute from xml
Parameters:
data | the Xml object |
---|---|
att | the name of the attribute |
default_ | what to return if the value doesn't exist |
Returns:
the attribute as an int if it exists, otherwise returns default
staticxml_name(data:Xml):String
For conveniently getting the very common "name" attribute, with backwards-compatibility for the old "id" attribute if name is not found @return
Parameters:
data |
---|
staticxml_pt(data:Xml, att:String, ?default_:FlxPoint):FlxPoint
Safety wrapper for reading a point attribute from xml
Parameters:
data | the Xml object |
---|---|
att | the name of the attribute |
default_ | what to return if the value doesn't exist |
Returns:
the attribute as a point if it exists, otherwise returns default
staticxml_str(data:Xml, att:String, lower_case:Bool = false, default_str:String = ""):String
Safety wrapper for reading a string attribute from xml
Parameters:
data | the Xml object |
---|---|
att | the name of the attribute |
lower_case | force lower_case or not |
what | to return if it is "" |
Returns:
the attribute as a string if it exists, otherwise returns ""