API Documentation for: 0.0.1
Show:

AssetManager Class

Defined in: AssetManager:8
Namespace: cloudkid

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

Properties

Methods

getAnims

(
  • anims
  • [maxDigits=4]
  • [outObj]
)
Object static

Defined in getAnims:291

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:

  • anims Object

    The dictionary of animation assets

  • [maxDigits=4] Int optional

    Maximum number of digits, like 4 for an animation exported as anim_0001.png

  • [outObj] Object optional

    If already using an return object

Returns:

Object:

An collection of PIXI.Textures for each animation id suitable for use in PIXI.MovieClip

getPreferredScale

() Number static

Get the preferred scale amount

Returns:

Number:

The scale amount associated with the preferred size

getPreferredSize

() String static

Get the alias of the preferred size to use

Returns:

String:

The alias for the preferred size

getUrl

(
  • assetId
)
static

Defined in getUrl:203

Get a asset url by asset id

Parameters:

  • assetId String

    The unique asset id

Returns:

The url of the asset at the appropriate size.

init

(
  • config
  • width
  • height
)
static

Defined in init:83

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
                }
          }

Parameters:

  • config Object

    The configuration file which contains keys for "path", "scale", "sizing", "assets"

  • width Number

    The stage width

  • height Number

    The stage height

pickScale

(
  • width
  • height
)
private static

Defined in pickScale:181

Pick the preferred scale based on the screen resolution

Parameters:

  • width Number

    The stage width

  • height Number

    The stage height

unload

(
  • assetOrAsset
)
static

Defined in unload:245

Unload an asset or list of assets.

Parameters:

  • assetOrAsset Array | String

    The collection of asset ids or single asset id

unloadAsset

(
  • asset
)
private static

Defined in unloadAsset:267

Unload an asset

Parameters:

  • asset String

    The asset id to unload

Properties

assets

Object private static

Defined in assets:36

Dictionary of assets by asset id

assetUrlCache

Object private static

Defined in assetUrlCache:44

The cache of asset url paths

lowHW

Boolean static

Defined in lowHW:76

If we should use low hardware, if we know we're on a slow device

paths

Object private static

Defined in paths:60

The paths to each resolution folder, e.g., {"sd":"images/sd/", "tiny":"images/tiny/"}

scales

Object final static

Defined in scales:19

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().

scales

Object private static

Defined in scales:52

The scaling value for each asset size id, e.g., {"sd" : 1, "tiny" : 2}

sizeOrder

Array private static

Defined in sizeOrder:68

The collection of perferred size to load

sizes

Array private static

Defined in sizes:28

The available size definitions, e.g., {"maxSize":400, "order": ["tiny", "sd"]}