Jet Link Simulations

Jet Link Simulations

  • Docs
  • API Reference
  • Help

AssetManager

A class similar to PIXI's Loader.shared that is intended to load resources for an entire Sandy application while providing many utility/helper functions to handle various types of sprites and data for the many resources a screen can have.

JLS.loaders.AssetManager

class AssetManager(directories)

    // Implementation example - shorten for brevity
    import { Screen, Device } from 'path/to/core'
    import { AssetManager, SAM } from 'path/to/loaders'

    const CONFIG                    = require('path/to/config').data


    const CenterTouchScreen         = new Screen(CONFIG, {
        . . .
        resources: {
            images: {
                background: 'RJ45_CenterTouchscreen_background_PROD.png',
            },
        },
    });


    const LANDING_GEAR_UNIT         = new Device({
        . . .
        resources: {
            images: {
                spritesheet: 'RJ45_GEAR_Spritesheet.json',
            }
        }
    });


    const PILOT_RMU_UNIT         = new Device({
        . . .
        // let's say this device doesn't have any assets for example
    });


    AssetManager.shared // or SAM (alias of AssetMananger.shared)
        .addObjAssets('screen', CenterTouchScreen, CenterTouchScreen.load)
        .addObjAssets('device', LANDING_GEAR_UNIT, LANDING_GEAR_UNIT.load)
        .load(() => {
            // If this device doesn't have any assets, you can simply call load 
            // on the device after all assets have been loaded and the Screen have been loaded
            PILOT_RMU_UNIT.load()
            
            // do other important stuff here that depends on all assets being loaded
            // for example set a main container for display and begin rendering

            // Set a screen to be the main container for the "scene."
            // This will usually be a JLS.Screen, but can be any PIXI.Container object
            displayEngine.set(TestScreen)


            // Boot the screen and devices
            CenterTouchScreen.boot()

            // Begin rendering the display. This is the most important step!!! If this isn't 
            // done, you won't see anything because it is not continously rendering anything.
            GameEngine.register(displayEngine.render)
        })
    

options

The word "options" is used somewhat loosely here as most of the fields are required. Actual optional parameters will have an optional flag.

NameTypeDefaultDescription
directoriesobject{ images: 'images', sounds: 'sounds' }optional The path to store each type of asset.

Members

directories

A reference to the path being used to store each type of asset.

parameters

NameTypeDefaultDescription
directoriesobject{ images: 'images', sounds: 'sounds' }optional The path to store each type of asset.

shared static

A premade instance of the loader that can be used to load resources. If one doesn't exist, a new instance is created with default options and returned.

Instead of importing AssetManager.shared, the alias SAM can be used for the shared asset manger.

all

Returns all the assets of the manager.

Methods

This class extends PIXI.Loader so all it's methods are available on the class in addition to the custom ones below.

addObjectAssets(type, obj, callback, options)

Loads the assets on a specified object such as a screen or device.

parameters

NameTypeDefaultDescription
typestring---The type of object that assets need to be loaded for. Options: screen, device
objJLS.Screen or JLS.Device---A reference to the actual object.
callbackfunction---A function to call when the assets have finished loading.

addAsset(resourceType, resourcePath, assetPrefix)

Loads the specified asset and gives it a keyname to be stored globally and retrieved later.

parameters

NameTypeDefaultDescription
resourceTypestring---The type or category of the asset. Options: images, sounds
resourcePathstring---The path of the resource to load
assetPrefixstringglobalThe prefix to add as part of the key when retrieving the asset.

setAsset(assetId, asset)

Saves an asset to the manager's asset collection. Can be used to set assets not created in the loading/parsing process of the AssetManager. Returns the asset if saved successfully. Else will return undefined.

parameters

NameTypeDefaultDescription
assetIdstring---The asset key to use when retrieving the asset from the shared asset manager.
assetobject---The asset to save to the asset loader. Can be any PIXI.Container,.DisplayObject,.Sprite

setTexture(textureId, textureId)

Saves a new texture to the manager's texture directory

parameters

NameTypeDefaultDescription
textureIdstring---The unique id to use for the texture
texturePIXI.Texture---The actual texture to save to the loader

getTexture(textureId)

Retrieves an asset from the manager's texture directory.

parameters

NameTypeDefaultDescription
textureIdstring---The unique id of the texture to retrieve

getAsset(assetId)

Retrieves an asset from the manager's asset collection. If no asset found using the specified assetId, will return undefined.

parameters

NameTypeDefaultDescription
assetIdstring---The id that was used to set it, now used to retrieve the asset.

get(assetId)

Alias of getAsset

getClone(assetId)

Creates a new instance (or copy) of a sprite using the saved texture.

parameters

NameTypeDefaultDescription
assetIdstring---The id that was used to set it, now used to retrieve the asset.

init()

"Initializes" the class. Called either from constructor or as public method. In this case, it is called as soon as the class is constructed.

  • class AssetManager(directories)
  • Members
    • directories
    • shared static
    • all
  • Methods
    • addObjectAssets(type, obj, callback, options)
    • addAsset(resourceType, resourcePath, assetPrefix)
    • setAsset(assetId, asset)
    • setTexture(textureId, textureId)
    • getTexture(textureId)
    • getAsset(assetId)
    • get(assetId)
    • getClone(assetId)
    • init()
Jet Link Simulations
Docs
Getting StartedGuidesAPI Reference
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Copyright © 2020 Name or Your Company Name