Various utilities, that have no specific Util class.
Static methods
staticinlineaddEndZeros(str:String, num:Int):String
Add several zeros at the end of a string, so that 2
becomes 20
, useful for ms.
Parameters:
str | String to add zeros |
---|---|
num | The length required |
staticaddMissingFolders(path:String):String
Creates eventual missing folders to the specified path
WARNING: eventual files in path
will be considered as folders! Just to make possible folders be named as songs.json
for example
Parameters:
path | Path to check. |
---|
Returns:
The initial Path.
staticinlineaddZeros(str:String, num:Int):String
Add several zeros at the beginning of a string, so that 2
becomes 02
.
Parameters:
str | String to add zeros |
---|---|
num | The length required |
staticautoSetFormat(text:FlxText, formats:Array<TextFormat>):FlxText
Sets automatically all the compatible formats to a text.
WARNING: These are dependant from the font, so if the font doesn't support for example the bold
format it won't work!
Parameters:
text | Text to set the format for |
---|---|
formats | Array of the formats (to get the formats from a node, you can use |
staticinlinebrowsePath(path:String):Void
Browse a path in the operating system's explorer
Parameters:
null | path |
---|
staticinlinecameraCenter(obj:FlxObject, cam:FlxCamera, axes:FlxAxes = XY):Void
Centers an object in a camera's field, basically screenCenter()
but camera.width
and camera.height
are used instead of FlxG.width
and FlxG.height
.
Parameters:
obj | Sprite to center |
---|---|
cam | Camera |
axes | Axes (XY) |
staticcloneProperty(toTarget:Dynamic, fields:OneOfTwo<String, Array<OneOfTwo<String, Int>>>, fromTarget:Dynamic):Dynamic
staticcoolTextFile(path:String):Array<String>
Allows you to split a text file from a path, into a "cool text file", AKA a list. Allows for comments. For example,
# comment
test1
test2
will return ["test1", "test2"]
Parameters:
path |
---|
Returns:
Array
staticinlinecopyColorTransform(color1:ColorTransform, color2:ColorTransform):Void
Copies a color transform from color1 to color2
Parameters:
color1 | Color transform to copy to |
---|---|
color2 | Color transform to copy from |
staticdeepFlatten(arr:Array<Dynamic>, ?result:Array<Dynamic>):Array<Dynamic>
Deep flattens an array.
Example: deepFlatten([1, [2, 3], 4])
will return [1, 2, 3, 4]
Parameters:
arr | Array to flatten |
---|---|
result | Result array |
staticdeleteFolder(delete:String):Void
Deletes a folder recursively
Parameters:
delete | Path to the folder. |
---|
staticinlinefirst<T>(array:Array<T>):T
Returns the first element of an Array
Parameters:
array | Array |
---|
Returns:
T Last element
staticinlinefloorInt(e:Float):Int
Equivalent of Math.floor
, except doesn't require a Int -> Float -> Int conversion.
Parameters:
e | Value to get the floor of. |
---|
staticinlineflxeaseFromString(mainEase:String, ?suffix:String):Null<EaseFunction>
Gets the FlxEase from a string.
Parameters:
mainEase | Main ease |
---|---|
suffix | Suffix (Ignored if |
staticformatNumberRange(numbers:Array<Int>, separator:String = ","):String
Converts an array of numbers into a string of ranges. Example: [1,2,3,5,7,8,9,8,7,6,5] -> "1..3,5,7..9,8..5"
Parameters:
numbers | Array of numbers |
---|---|
separator | Separator between ranges |
Returns:
String representing the ranges
staticinlinefpsLerp(v1:Float, v2:Float, ratio:Float):Float
Alternative linear interpolation function for each frame use, without worrying about framerate changes.
Parameters:
v1 | Begin value |
---|---|
v2 | End value |
ratio | Ratio |
Returns:
Float Final value
staticinlinegetAtt(xml:Access, name:String):Null<Null<String>>
Gets an XML attribute from an Access
abstract, without throwing an exception if invalid.
Example: xml.getAtt("test").getDefault("Hello, World!");
Parameters:
xml | XML to get the attribute from |
---|---|
name | Name of the attribute |
staticgetColorFromDynamic(c:Dynamic):Null<FlxColor>
Tries to get a color from a Dynamic
variable.
Parameters:
c |
|
---|
Returns:
The result color, or null
if invalid.
staticinlinegetDefaultFloat(v:Float, defaultValue:Float):Float
For use when using Std.parseFloat, if not using that then use getDefault
.
Parameters:
v | The value |
---|---|
defaultValue | The default value |
Returns:
The return value
staticinlinegetFPSRatio(ratio:Float, ?delta:Float):Float
Modifies a lerp ratio based on current FPS to keep a stable speed on higher framerate.
Parameters:
ratio | Ratio |
---|---|
delta | Delta/Elapsed for the fps-modified ratio (Optional) |
Returns:
FPS-Modified Ratio
staticgetLastExceptionStack():String
Gets the last exception stack. Useful for debugging.
staticgetLuminance(color:FlxColor):Float
Gets the luminance of the given color
Parameters:
color | Color to use |
---|
Returns:
Number between 0 and 1
staticinlinegetMacroAbstractClass(className:String):Class<Dynamic>
Gets the macro class created by hscript-improved for an abstract / enum
staticgetSizeString(size:Float):String
Returns a string representation of a size, following this format: 1.02 GB
, 134.00 MB
Parameters:
size | Size to convert to string |
---|
Returns:
String Result string representation
staticgetSizeString64(size:Float64):String
Returns a string representation of a size, following this format: 1.02 GB
, 134.00 MB
, using Float64 on cpp targets
Parameters:
size | Size to convert to string |
---|
Returns:
String Result string representation
staticimageHasFrameData(path:String):String
! REQUIRES FULL PATH!!!
Parameters:
path |
---|
Returns:
Bool
staticinlineindexOfFromLast<T>(array:Array<T>, element:T):Int
Basically indexOf, but starts from the end.
Parameters:
array | Array to scan |
---|---|
element | Element |
Returns:
Index, or -1 if unsuccessful.
staticinlinekeyToString(key:Null<FlxKey>):String
Returns a simple string representation of a FlxKey. Used in Controls options.
Parameters:
key | Key |
---|
Returns:
Simple representation
staticinlinelast<T>(array:Array<T>):T
Returns the last element of an Array
Parameters:
array | Array |
---|
Returns:
T Last element
staticinlinelerpColor(color1:FlxColor, color2:FlxColor, ratio:Float, fpsSensitive:Bool = false):FlxColor
Lerps from color1 into color2 (Shortcut to FlxColor.interpolate
)
Parameters:
color1 | Color 1 |
---|---|
color2 | Color 2 |
ratio | Ratio |
fpsSensitive | Whenever the ratio should be fps sensitive (adapted when game is running at 120 instead of 60) |
staticloadAnimatedGraphic(spr:FlxSprite, path:String, fps:Float = 24.0):FlxSprite
Loads an animated graphic, and automatically animates it.
Parameters:
spr | Sprite to load the graphic for |
---|---|
path | Path to the graphic |
staticinlinemaxInt(p1:Int, p2:Int):Int
Equivalent of Math.max
, except doesn't require a Int -> Float -> Int conversion.
Parameters:
p1 | |
---|---|
p2 |
Returns:
return p1 < p2 ? p2 : p1
staticinlineminInt(p1:Int, p2:Int):Int
Equivalent of Math.min
, except doesn't require a Int -> Float -> Int conversion.
Parameters:
p1 | |
---|---|
p2 |
Returns:
return p1 > p2 ? p2 : p1
staticinlinenumberArray(max:Int, min:Int = 0):Array<Int>
Returns an array of number from min to max. Equivalent of [for (i in min...max) i]
.
Parameters:
max | Max value |
---|---|
min | Minimal value (0) |
Returns:
Array
staticparseJson(assetPath:String):Dynamic
Shortcut to parse JSON from an Asset path
Parameters:
assetPath | Path to the JSON asset. |
---|
staticinlineparseJsonString(str:String):Dynamic
Shortcut to parse a JSON string
Parameters:
str | Path to the JSON string |
---|
Returns:
Parsed JSON
staticparseNumberRange(input:String):Array<Int>
Converts a string of "1..3,5,7..9,8..5" into an array of numbers like [1,2,3,5,7,8,9,8,7,6,5]
Parameters:
input | String to parse |
---|
Returns:
Array of numbers
staticparseProperty(target:Dynamic, fields:OneOfTwo<String, Array<OneOfTwo<String, Int>>>):Dynamic
staticinlineplayMenuSFX(menuSFX:CoolSfx = SCROLL, volume:Float = 1):FlxSound
Plays a specified Menu SFX.
Parameters:
menuSFX | Menu SFX to play |
---|---|
volume | At which volume it should play |
staticplayMenuSong(fadeIn:Bool = false):Void
Plays the main menu theme.
Parameters:
null | fadeIn |
---|
staticplayMusic(path:String, Persist:Bool = false, Volume:Float = 1, Looped:Bool = true, DefaultBPM:Float = 102, ?Group:FlxSoundGroup):Void
Plays music, while resetting the Conductor, and taking info from INI in count.
Parameters:
path | Path to the music |
---|---|
Persist | Whenever the music should persist while switching states |
DefaultBPM | Default BPM of the music (102) |
Volume | Volume of the music (1) |
Looped | Whenever the music loops (true) |
Group | A group that this music belongs to (default) |
staticpointToScreenPosition(object:FlxPoint, ?camera:FlxCamera, ?result:FlxPoint):Null<FlxPoint>
Returns the screen position of an point, while taking the camera zoom into account.
Parameters:
object | Any |
---|---|
camera | The desired "screen" coordinate space. If |
result | Optional arg for the returning point |
Returns:
The screen position of the object.
staticinlinepositiveModulo(dividend:Float, divisor:Float):Float
Applies the % operator, but without any negatives.
Parameters:
dividend | The intial value. The left side of the equation. |
---|---|
divisor | What to modulo by. The right side of the equation. |
Returns:
A positive reminder of dividend / divisor
.
staticinlinepositiveModuloInt(dividend:Int, divisor:Int):Int
Applies the % operator, but without any negatives. But it's an int.
Parameters:
dividend | The intial value. The left side of the equation. |
---|---|
divisor | What to modulo by. The right side of the equation. |
Returns:
A positive reminder of dividend / divisor
.
staticpreloadCharacter(name:String, ?spriteName:String):Void
Preloads a character.
Parameters:
name | Character name |
---|---|
spriteName | (Optional) sprite name. |
staticinlinepushGroup<T>(array:Array<T>, args:Rest<T>):Array<T>
Push an entire group into an array.
Parameters:
array | Array to push the group into |
---|---|
...args | Group entries |
Returns:
Array
staticinlinepushOnce<T>(array:Array<T>, element:T):Void
Pushes an element to an array, but only if it doesn't already exist.
Parameters:
array | Array to push to |
---|---|
element | Element to push |
staticinlinequantize(Value:Float, Quant:Float):Float
Quantizes a value to a certain amount.
Example: quantize(2.5543, 1)
will return 2.0
Example: quantize(2.5543, 10)
will return 2.5
Example: quantize(2.5543, 100)
will return 2.55
Parameters:
Value | Value to quantize |
---|---|
Quant | Quantization amount |
staticinlineremoveIP(msg:String):String
Replaces in a string any kind of IP with [Your IP]
making the string safer to trace.
Parameters:
msg | String to check and edit |
---|
Returns:
String Result without any kind of IP
staticinlinereplay(sound:FlxSound):Void
Stops a sound, set its time to 0 then play it again.
Parameters:
sound | Sound to replay. |
---|
staticresetSprite(spr:FlxSprite, x:Float, y:Float):Void
Resets an FlxSprite
Parameters:
spr | Sprite to reset |
---|---|
x | New X position |
y | New Y position |
staticinlinesafeAddAttributes(path:String, attrib:OneOfTwo<FileAttribute, Int>, useAbsolute:Bool = true):Int
Adds one (or more) file attributes to a file or a folder adding eventual missing folders in the path
(WARNING: Only works on windows
for now. On other platforms the return code it's always going to be 0
but still creates eventual missing folders if the platforms allows it to).
Parameters:
path | Path to the file or folder |
---|---|
attrib | The attribute(s) to add (WARNING: There are some non settable attributes, such as the |
useAbsolute | If it should use the absolute path (By default it's |
Returns:
The result code: 0
means that it failed setting
staticinlinesafeGetAttributes(path:String, useAbsolute:Bool = true):FileAttributeWrapper
Gets file attributes from a file or a folder adding eventual missing folders in the path
(WARNING: Only works on windows
for now. On other platforms the attributes' value it's always going to be 0
-thanks to the wrapper you can also use isNothing
for checking- but still creates eventual missing folders if the platforms allows it to).
Parameters:
path | Path to the file or folder |
---|---|
useAbsolute | If it should use the absolute path (By default it's |
Returns:
The attributes through the FileAttributeWrapper
staticinlinesafeRemoveAttributes(path:String, attrib:OneOfTwo<FileAttribute, Int>, useAbsolute:Bool = true):Int
Removes one (or more) file attributes to a file or a folder adding eventual missing folders in the path
(WARNING: Only works on windows
for now. On other platforms the return code it's always going to be 0
but still creates eventual missing folders if the platforms allows it to).
Parameters:
path | Path to the file or folder |
---|---|
attrib | The attribute(s) to remove (WARNING: There are some non settable attributes, such as the |
useAbsolute | If it should use the absolute path (By default it's |
Returns:
The result code: 0
means that it failed setting
staticsafeSaveFile(path:String, content:OneOfTwo<String, Bytes>, showErrorBox:Bool = true):Void
Safe saves a file (even adding eventual missing folders) and shows a warning box instead of making the program crash
Parameters:
path | Path to save the file at. |
---|---|
content | Content of the file to save (as String or Bytes). |
staticinlinesafeSetAttributes(path:String, attrib:OneOfThree<FileAttribute, FileAttributeWrapper, Int>, useAbsolute:Bool = true):Int
Sets file attributes to a file or a folder adding eventual missing folders in the path
(WARNING: Only works on windows
for now. On other platforms the return code it's always going to be 0
but still creates eventual missing folders if the platforms allows it to).
Parameters:
path | Path to the file or folder |
---|---|
attrib | The attribute(s) to set (WARNING: There are some non settable attributes, such as the |
useAbsolute | If it should use the absolute path (By default it's |
Returns:
The result code: 0
means that it failed setting
staticsetFieldDefault<T>(v:Dynamic, name:String, defaultValue:T):T
Sets a field's default value, and returns it. In case it already exists, returns the existing one.
Parameters:
v | Dynamic to set the default value to |
---|---|
name | Name of the value |
defaultValue | Default value |
Returns:
T New/old value.
staticinlinesetMusic(frontEnd:SoundFrontEnd, music:FlxSound):Void
Sets a SoundFrontEnd's music to a FlxSound.
Example: FlxG.sound.setMusic(music);
Parameters:
frontEnd | SoundFrontEnd to set the music of |
---|---|
music | Music |
staticinlinesetSpriteSize(sprite:FlxSprite, width:Float, height:Float):Void
Equivalent of setGraphicSize
, except that it can accept floats and automatically updates the hitbox.
Parameters:
sprite | Sprite to set the size of |
---|---|
width | Width |
height | Height |
staticinlinesetUnstretchedGraphicSize(sprite:FlxSprite, width:Int, height:Int, fill:Bool = true, maxScale:Float = 0):Void
Allows you to set a graphic size (ex: 150x150), with proper hitbox without a stretched sprite.
Parameters:
sprite | Sprite to apply the new graphic size to |
---|---|
width | Width |
height | Height |
fill | Whenever the sprite should fill instead of shrinking (true) |
maxScale | Maximum scale (0 / none) |
staticsortAlphabetically(array:Array<String>, lowercase:Bool = false):Array<String>
Sorts an array alphabetically.
Parameters:
array | Array to sort |
---|---|
lowercase | Whenever the array should be sorted in lowercase |
staticswitchAnimFrames(anim1:FlxAnimation, anim2:FlxAnimation):Void
Switches frames from 2 FlxAnimations.
Parameters:
anim1 | First animation |
---|---|
anim2 | Second animation |
staticinlinetimeToStr(time:Float):String
Converts a timestamp to a readable format such as 01:22
(mm:ss
)
staticworldToScreenPosition(object:FlxObject, ?camera:FlxCamera, ?result:FlxPoint):Null<FlxPoint>
Returns the screen position of an object, while taking the camera zoom into account.
Parameters:
object | Any |
---|---|
camera | The desired "screen" coordinate space. If |
result | Optional arg for the returning point |
Returns:
The screen position of the object.