Static variables
staticdefaultSoundExtension:String = "mp3"
The default sound format to be assumed when unspecified, only affects calls to
FlxAssets.getSound
which are not common. Currently set to ".ogg" on non-flash targets
for backwards compatibility reasons.
Static methods
staticbuildFileReferences(directory:String = "assets/", subDirectories:Bool = false, ?include:Null<Expr>, ?exclude:Null<Expr>, ?rename:String ‑> Null<String>, listField:String = "allFiles"):Array<Field>
Reads files from a directory relative to this project and generates public static inline
variables containing the string paths to the files in it.
Example usage:
@:build(flixel.system.FlxAssets.buildFileReferences("assets/images/"))
class Images {}
Renaming Duplicates
If you have files with the same names, whichever file is nested deeper or found later
will be ignored. You can provide rename
function to deal with this case. The function takes a filepath
(a relative filepath from the Project.xml
) and returns a field name used to access that path.
Returning null
means "ignore the file".
// assets structure:
// assets/music/hero.ogg
// assets/sounds/hero.ogg
// AssetPaths.hx
@:build(flixel.system.FlxAssets.buildFileReferences("assets", true, null, null,
function renameFileName(name:String):Null<String>
{
return name.toLowerCase()
.split("/").join("_")
.split("-").join("_")
.split(" ").join("_")
.split(".").join("__");
}
))
class AssetPaths {}
// somewhere in your code
FlxG.sound.play(AssetPaths.assets_music_hero__ogg);
FlxG.sound.play(AssetPaths.assets_sounds_hero__ogg);
Parameters:
directory | The directory to scan for files | ||
---|---|---|---|
subDirectories | Whether to include subdirectories | ||
include | A string or | ||
exclude |
will exclude .ogg files and everything in the exclude folder | ||
rename | A function that takes the file path and returns a valid haxe field name | ||
listField | If not an empty string, it adds static public field with the given name with an array of every file in the directory |
See also:
staticinlinegetBitmapFromClass(source:Class<Dynamic>):BitmapData
Generates BitmapData from specified class. Less typing.
Parameters:
source | BitmapData class to generate BitmapData object from. |
---|
Returns:
Newly instantiated BitmapData object.
staticgetSound(id:String):Sound
Loads an OpenFL sound asset from the given asset id. If an extension not provided the
defaultSoundExtension
is used (defaults to "ogg" on non-flash targets).
Parameters:
id | The asset id of the local sound file. |
---|
Returns:
The sound file.
staticresolveBitmapData(Graphic:FlxGraphicSource):BitmapData
Takes Dynamic object as a input and tries to convert it to BitmapData:
1) if the input is BitmapData, then it will return this BitmapData;
2) if the input is Class
Parameters:
Graphic | input data to get BitmapData object for. |
---|
Returns:
BitmapData for specified Dynamic object.
staticresolveKey(Graphic:FlxGraphicSource, ?Key:String):String
Takes Dynamic object as a input and tries to find appropriate key String for its BitmapData:
1) if the input is BitmapData, then it will return second (optional) argument (the Key);
2) if the input is Class
Parameters:
Graphic | input data to get string key for. |
---|---|
Key | optional key string. |
Returns:
Key String for specified Graphic object.