Static variables

@:value("Monsterrat")staticFONT_DEBUGGER:String = "Monsterrat"

@:value("Nokia Cellphone FC Small")staticFONT_DEFAULT:String = "Nokia Cellphone FC Small"

@:value("mp3")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

@:value({ listField : "allFiles", subDirectories : false, directory : "assets/" })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 EReg of files to include Example: "*.jpg\|*.png\|*.gif" will only add files with that extension

exclude
A string or EReg of files to exclude. Example: `"exclude/\*.ogg"`

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:

staticdrawLogo(graph:Graphics):Void

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, then it will create BitmapData from this class; 3) if the input is String, then it will get BitmapData from openfl.Assets; 4) it will return null in any other case.

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, then it will return the name of this class; 3) if the input is String, then it will return it; 4) it will return null in any other case.

Parameters:

Graphic

input data to get string key for.

Key

optional key string.

Returns:

Key String for specified Graphic object.