Utility functions, inlined where possible

Static methods

staticFU(str:String):String

Return string with first character uppercase'd @return

Parameters:

str

staticFUL(str:String):String

Return string with first character uppercase'd, rest lowercase'd @return

Parameters:

str

staticFU_(str:String):String

staticinlineaabb_test(a:FlxObject, b:FlxObject):Bool

@:value({ multB : 1, multA : 1 })staticinlineaabb_test_mult(a:FlxObject, b:FlxObject, multA:Float = 1, multB:Float = 1):Bool

staticapplyResize(resize_ratio:Float, resize_ratio_axis:Int, w:Float, h:Float, ?pt:FlxPoint):FlxPoint

staticinlinebitStringDimensions(str:String):Point

Get the dimensions of a bit string

staticbmpToArrayIntLayer(color_index:Int, bd:BitmapData):Array<Int>

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.

staticboolify(str:String):Bool

@:value({ centerY : true, centerX : true })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?

staticinlinecircle_test(x1:Float, y1:Float, r1:Float, x2:Float, y2:Float, r2:Float):Bool

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

@:value({ op : "==" })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

staticinlinecopyAccess(fast:Access):Access

staticinlinecopyXml(data:Xml):Xml

staticinlinedirStr(XX:Int, YY:Int):String

staticinlinedisposeXML(thing:Dynamic):Void

@:value({ _default : null })staticfield(object:Dynamic, field:String, ?_default:Dynamic):Dynamic

@:value({ extension : ".ttf", style : "" })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

@:value({ style : "" })staticinlinefontStr(str:String, style:String = ""):String

Given something like "verdana" and "bold" returns "assets/fonts/verdanab" @return

Parameters:

str
style

staticformatXml(_xml:Xml):String

staticinlinefs(data:Dynamic):FlxSprite

staticinlinefsx(data:Dynamic):FlxUISprite

staticinlinegetLocList(xmin:Int, ymin:Int, xmax:Int, ymax:Int):Array<FlxPoint>

@:value({ folder : "" })staticgetXML(str:String, folder:String = ""):Dynamic

staticget_gfx(str:String):String

@:value({ suppressError : false, dir4 : "", dir3 : "", dir2 : "", dir1 : "" })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

staticisStrInt(str:String):Bool

staticisStrNum(str:String):Bool

@:value({ dir : "assets/json/", extension : "json" })staticjson(str:String, extension:String = "json", dir:String = "assets/json/"):Dynamic

@:value({ checkFlxBitmap : false, Smooth : true })staticloadImageScaleToHeight(src:String, Height:Float, Smooth:Bool = true, checkFlxBitmap:Bool = false):String

@:value({ fixAlphaChannel : false, checkFlxBitmap : false, smooth : true })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

@:value({ smooth : true })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

@:value({ padChar : "0" })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

@:value({ default_color : 0x000000, safe : false, cast32Bit : false })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

staticinlinepoint_circle_test(x:Float, y:Float, cx:Float, cy:Float, r:Float):Bool

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

@:value({ Smooth : true, TileH : -1, TileW : -1 })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

@:value({ smooth : true, H : -1, W : -1 })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

staticsetButtonLabel(btn:IFlxUIButton, str:String):Void

Available since

2.1.0

.

staticinlinesfx(str:String):String

staticinlinesplitBitString(str:String):Array<Int>

Splits a binary string with endlines into a big long int array

staticstrCase(str:String, code:String):String

staticinlinetest_float(f1:Float, test:String, f2:Int):Bool

staticinlinetest_int(i1:Int, test:String, i2:Int):Bool

@:value({ dir : "assets/xml/", getAccess : true, extension : "xml" })staticxml(id:String, extension:String = "xml", getAccess:Bool = true, dir:String = "assets/xml/"):Dynamic

@:value({ default_ : false })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

@:value({ defaultColor : null, cast32Bit : true })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

@:value({ cast32Bit : true })staticxml_colorArray(data:Xml, att:String, cast32Bit:Bool = true):Array<FlxColor>

@:value({ default_ : 0 })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_fArray(data:Xml, att:String):Array<Float>

@:value({ test : true })staticinlinexml_gfx(data:Xml, att:String, test:Bool = true):String

@:value({ default_ : 0 })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_iArray(data:Xml, att:String):Array<Int>

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

@:value({ default_ : null })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

@:value({ default_str : "", lower_case : false })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 ""

@:value({ default_ : null, lowerCase : true })staticxml_strArray(data:Xml, att:String, lowerCase:Bool = true, ?default_:Array<String>):Array<String>