AssetManager Class
AssetManager is responsible for managing different resolutions of assets and spritesheets based on the resolution of the stage. This is a helpful optimization for PIXI because some low-hardware devices have a problem keeping up with larger images, or just refuse large images entirely. The AssetManager does not load assets itself, or keep track of what is loaded. It merely assists in loading the appropriate assets, as well as easily unloading assets when you are done using them.
Item Index
Methods
- getAnims static
- getPreferredScale static
- getPreferredSize static
- getUrl static
- init static
- pickScale static
- unload static
- unloadAsset static
Methods
getAnims
-
anims
-
[maxDigits=4]
-
[outObj]
Assemble a dictionary of Texture arrays representing animations from the PixiJS texture cache. Example of a getAnims() call:
var animationDictionary = AssetManager.getAnims(
{
"bobIdleHappy":{"name":"bob_idle_happy#", "numberMin":1, "numberMax":139},
"bobIdleNeutral":{"name":"bob_idle_neutral#", "numberMin":1, "numberMax":140},
"bobIdleMad":{"name":"bob_idle_mad#", "numberMin":1, "numberMax":140},
"bobPos":{"name":"bob_react_pos#", "numberMin":1, "numberMax":23},
"bobNeg":{"name":"bob_react_neg#", "numberMin":1, "numberMax":31},
},
4);
Parameters:
Returns:
An collection of PIXI.Textures for each animation id suitable for use in PIXI.MovieClip
getPreferredScale
()
Number
static
Get the preferred scale amount
Returns:
The scale amount associated with the preferred size
getPreferredSize
()
String
static
Get the alias of the preferred size to use
Returns:
The alias for the preferred size
getUrl
-
assetId
Get a asset url by asset id
Parameters:
-
assetId
StringThe unique asset id
Returns:
The url of the asset at the appropriate size.
init
-
config
-
width
-
height
Initialize the asset manager. The asset manager is capable of taking different paths for each size of image as well as an animation file path for Spine animations. Image assets do not have to exist in each size. Fonts are marked for unloading purposes. Example config file:
{
"path": {
"sd": "images/sd/",
"tiny": "images/tiny/",
"anim": "anims/"
},
"scale": {
"sd": 1,
"tiny": 2
},
"sizing": [
{
"maxSize": 400,
"order": [
"tiny",
"sd"
]
},
{
"maxSize": 10000,
"order": [
"sd",
"tiny"
]
}
],
"assets": {
"transition": {
"src": "transition.json",
"anim": true
},
"TransitionSheet": {
"src": "ui/TransitionSheet.json",
"sd":true,
"tiny":true
},
"FoodTruck_Title": {
"src": "backgrounds/FoodTruck_Title.jpg",
"sd":true,
"tiny":true
},
"StartButton": {
"src": "ui/StartButton.png",
"sd":true,
"tiny":false
},
"LevelTitleFont": {
"src": "ui/LevelTitleFont.xml",
"sd": true,
"tiny": false,
"isFont": true
}
}
pickScale
-
width
-
height
Pick the preferred scale based on the screen resolution
unload
-
assetOrAsset
Unload an asset or list of assets.
unloadAsset
-
asset
Unload an asset
Parameters:
-
asset
StringThe asset id to unload
Properties
paths
Object
private
static
The paths to each resolution folder, e.g., {"sd":"images/sd/", "tiny":"images/tiny/"}
scales
Object
final
static
Dictionary of scales by asset id. Use this to return your asset to normal size. Assets are only added to this dictionary after a url has been retrieved with getUrl().
sizes
Array
private
static
The available size definitions, e.g., {"maxSize":400, "order": ["tiny", "sd"]}