Accessed via FlxG.assets
. The main interface for the asset system. By default, OpenFl's
Asset system is used, which uses relative path strings to retrive assets, though you can completely
avoid Openfl's asset system by setting custom methods to the following dynamic fields: getAssetUnsafe
,
loadAsset
, exists
, isLocal
and list
.
Common Uses
The initial reason for making customizable asset system was to allow for "hot-reloading", or testing new assets in your game without recompiling, with each change. Say, if you would like a debug feature where you load assets from source assets, rather than the assets copied over to your export folder, you could overwrite this system to do just that.
Other potential uses for this are modding, bypassing the manifest and loading resources from a remote location.
Quick Setup for "Hot-Reloading"
To simplify the process mentioned above, the FLX_CUSTOM_ASSETS_DIRECTORY
flag was created.
By adding -DFLX_CUSTOM_ASSETS_DIRECTORY="assets"
to your lime build command
it will automatically grab assets from your project root's assets folder rather than, the
default "export/hl/bin/assets". This will only work with a single asset root folder with one
asset library and will use the openfl asset system if the asset id starts with "flixel/" or
tries to references a specific library using the format: "libName:asset/path/file.ext".
5.9.0
.Constructor
Variables
Methods
dynamicexists(id:String, ?type:FlxAssetType):Bool
Whether a specific asset ID and type exists. Can be set to a custom function to avoid the existing asset system.
Parameters:
id | The ID or asset path for the asset |
---|---|
type | The asset type to match, or null to match any type |
getAsset(id:String, type:FlxAssetType, useCache:Bool = true, ?logStyle:LogStyle):Null<Any>
Calls getAssetUnsafe
if the asset exists, otherwise logs that the asset is missing, via FlxG.log
Parameters:
id | The id of the asset, usually a path |
---|---|
type | The type of asset to look for, determines the type |
useCache | Whether to allow use of the asset cache (if one exists) |
logStyle | How to log, if the asset is not found. Uses |
dynamicgetAssetUnsafe(id:String, type:FlxAssetType, useCache:Bool = true):Null<Any>
Used by methods like getAsset
, getBitmapData
, getText
, their "unsafe" counterparts and
the like to get assets synchronously. Can be set to a custom function to avoid the existing
asset system. Unlike its "safe" counterpart, there is no log on missing assets
Parameters:
id | The id of the asset, usually a path |
---|---|
type | The type of asset to look for, determines the type |
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
The asset, if found, otherwise null
is returned
inlinegetBitmapData(id:String, useCache:Bool = false, ?logStyle:LogStyle):BitmapData
Gets an instance of a bitmap, logs when the asset is not found
Parameters:
id | The ID or asset path for the bitmap |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
A new BitmapData object
inlinegetBitmapDataUnsafe(id:String, useCache:Bool = false):BitmapData
Gets an instance of a bitmap. Unlike its "safe" counterpart, there is no log on missing assets
Parameters:
id | The ID or asset path for the bitmap |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
A new BitmapData object
inlinegetBytes(id:String, useCache:Bool = true, ?logStyle:LogStyle):Bytes
Gets the contents of a binary asset, logs when the asset is not found
Note: The default asset system does not cache binary assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
logStyle | How to log, if the asset is not found. Uses |
inlinegetBytesUnsafe(id:String, useCache:Bool = true):Bytes
Gets the contents of a binary asset. Unlike its "safe" counterpart, there is no log on missing assets
Note: The default asset system does not cache binary assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
inlinegetFont(id:String, useCache:Bool = true, ?logStyle:LogStyle):Font
Gets the contents of a font asset, logs when the asset is not found
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
logStyle | How to log, if the asset is not found. Uses |
inlinegetFontUnsafe(id:String, useCache:Bool = true):Font
Gets the contents of a font asset. Unlike its "safe" counterpart, there is no log on missing assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache |
inlinegetJson(id:String, useCache:Bool = true, ?logStyle:LogStyle):Null<Null<Dynamic>>
Gets the contents of a json-based asset, logs when the asset is not found
Note: The default asset system does not cache json assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
logStyle | How to log, if the asset is not found. Uses |
inlinegetJsonUnsafe(id:String, useCache:Bool = true):Null<Null<Dynamic>>
Gets the contents of a json-based asset. Unlike its "safe" counterpart, there is no log on missing assets
Note: The default asset system does not cache json assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
inlinegetSound(id:String, useCache:Bool = true, ?logStyle:LogStyle):Sound
Gets an instance of a sound, logs when the asset is not found.
Note: If the FLX_DEFAULT_SOUND_EXT
flag is enabled, you may omit the file extension
Parameters:
id | The ID or asset path for the sound |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
logStyle | How to log, if the asset is not found. Uses |
Returns:
inlinegetSoundAddExt(id:String, useCache:Bool = true, ?logStyle:LogStyle):Sound
Gets an instance of a sound, logs when the asset is not found
Parameters:
id | The ID or asset path for the sound |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
logStyle | How to log, if the asset is not found. Uses |
Returns:
inlinegetSoundUnsafe(id:String, useCache:Bool = true):Sound
inlinegetText(id:String, useCache:Bool = true, ?logStyle:LogStyle):String
Gets the contents of a text-based asset, logs when the asset is not found
Note: The default asset system does not cache text assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
logStyle | How to log, if the asset is not found. Uses |
inlinegetTextUnsafe(id:String, useCache:Bool = true):String
Gets the contents of a text-based asset. Unlike its "safe" counterpart, there is no log on missing assets
Note: The default asset system does not cache text assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
inlinegetXml(id:String, useCache:Bool = true, ?logStyle:LogStyle):Null<Null<Xml>>
Parses the contents of an xml-based asset into an Xml
object, logs when the asset is not found
Note: The default asset system does not cache xml assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
logStyle | How to log, if the asset is not found. Uses |
inlinegetXmlUnsafe(id:String, useCache:Bool = true):Null<Null<Xml>>
Parses the contents of an xml-based asset into an Xml
object.
Unlike its "safe" counterpart, there is no log on missing assets
Note: The default asset system does not cache xml assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
dynamicisLocal(id:String, ?type:FlxAssetType, useCache:Bool = true):Bool
Returns whether an asset is "local", and therefore can be loaded synchronously, or with the
getAsset
method, otherwise the loadAsset
method should be used.
Can be set to a custom function to avoid the existing asset system.
Parameters:
id | The ID or asset path for the asset |
---|---|
type | The asset type to match, or null to match any type |
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
Whether the asset is local
dynamiclist(?type:FlxAssetType):Array<String>
Returns a list of all assets (by type). Can be set to a custom function to avoid the existing asset system.
Parameters:
type | The asset type to match, or null to match any type |
---|
Returns:
An array of asset ID values
dynamicloadAsset(id:String, type:FlxAssetType, useCache:Bool = true):Future<Any>
Used by methods like loadBitmapData
, loadText
and the like to get assets asynchronously.
Can be set to a custom function to avoid the existing asset system.
Parameters:
id | The id of the asset, usually a path |
---|---|
type | The type of asset to look for, determines the type |
useCache | Whether to allow use of the asset cache (if one exists) |
inlineloadBitmapData(id:String, useCache:Bool = false):Future<BitmapData>
Loads a bitmap asset asynchronously
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
Returns a Future
which allows listeners to be added via methods like onComplete
inlineloadBytes(id:String, useCache:Bool = true):Future<Bytes>
Loads a binary asset asynchronously
Note: The default asset system does not cache binary assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
Returns a Future
which allows listeners to be added via methods like onComplete
inlineloadFont(id:String, useCache:Bool = true):Future<Font>
Loads a font asset asynchronously
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
Returns a Future
which allows listeners to be added via methods like onComplete
inlineloadJson(id:String, useCache:Bool = true):Future<Dynamic>
Loads a json asset asynchronously
Note: The default asset system does not cache json assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
Returns a Future
which allows listeners to be added via methods like onComplete
inlineloadSound(id:String, useCache:Bool = true):Future<Sound>
Loads a sound asset asynchronously
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
Returns a Future
which allows listeners to be added via methods like onComplete
inlineloadText(id:String, useCache:Bool = true):Future<String>
Loads a text asset asynchronously
Note: The default asset system does not cache text assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
Returns a Future
which allows listeners to be added via methods like onComplete
inlineloadXml(id:String, useCache:Bool = true):Future<Xml>
Loads an xml asset asynchronously
Note: The default asset system does not cache xml assets
Parameters:
id | The ID or asset path for the asset |
---|---|
useCache | Whether to allow use of the asset cache (if one exists) |
Returns:
Returns a Future
which allows listeners to be added via methods like onComplete