Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Asset

Hierarchy

  • EventEmitter
    • Asset

Index

Constructors

constructor

  • public constructor Asset

    Represents an asset to a game.
    

    Parameters

    • type: AssetType
    • Optional url: string

      Location path.

    Returns Asset

Properties

Private _attributes

_attributes: object

Type declaration

  • [key: string]: any

Private _data

_data: Object

Private _id

_id: string

Private _loadStrategy

_loadStrategy: AssetLoader

Private _state

_state: AssetState

Private _type

_type: AssetType

Private _url

_url: string

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: function): this

emit

  • emit(event: string | symbol, ...args: any[]): boolean

eventNames

  • eventNames(): Array<string | symbol>

getAttribute

  • getAttribute(key: string): any
  • public getAttribute

    Gets data details from this asset.
    

    Parameters

    • key: string

    Returns any

getData

  • getData(): any

getLoadStrategy

getMaxListeners

  • getMaxListeners(): number

getSource

  • getSource(): string
  • public getSource

    Returns the source location path of this asset.
    

    Returns string

getState

getType

isAttribute

  • isAttribute(key: string): boolean
  • public isAttribute

    Checks for existance of a data detail on this asset.
    

    Parameters

    • key: string

    Returns boolean

isReady

  • isReady(): boolean
  • public isReady

    Checks to see if the data has been loaded on this asset.
    

    Returns boolean

listenerCount

  • listenerCount(type: string | symbol): number

listeners

  • listeners(event: string | symbol): Function[]

load

  • public load

    Loads the asset data.
    
    Use onDataChange hook method to get notified when data has
    finished loading.
    

    Returns Promise<Asset>

on

  • on(event: string | symbol, listener: function): this

onDataChange

  • onDataChange(data: Object): void
  • public onDataChange

    Invoked when data changes.
    
    deprecated

    Use on(AssetEventType.DATA_CHANGE) instead.

    Parameters

    • data: Object

      Must be prepared to handle null.

    Returns void

onError

  • onError(error?: Object): void
  • public onError

    Invoked when there was an error while loading asset data.
    

    Note: Prior usage was a hook function. Now this should be treated as a protected method, however TypeScript doesn't have "friend" class support, and AssetLoader needs to invoke this method.

    Use

        on(AssetEvents.ERROR)
    

    OR

        load().catch((error) => { ... })
    

    to receive the error instead.

    Parameters

    • Optional error: Object

    Returns void

onStateChange

  • public hook onStateChange

    Invoked when state changes.
    
    deprecated

    Use on(AssetEventType.STATE_CHANGE) instead.

    Parameters

    • state: AssetState

      Possible values:

                                  - AssetState.NOT_LOADED
                               - AssetState.LOADING
                               - AssetState.LOADED
      

    Returns void

once

  • once(event: string | symbol, listener: function): this

prependListener

  • prependListener(event: string | symbol, listener: function): this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeAttribute

  • removeAttribute(key: string): void
  • public removeAttribute

    Removes a data attribute from this asset.
    

    Parameters

    • key: string

    Returns void

removeListener

  • removeListener(event: string | symbol, listener: function): this

setAttribute

  • setAttribute(key: string, value: any): void
  • public setAttribute

    Sets data details for this asset.
    

    Parameters

    • key: string
    • value: any

    Returns void

setData

  • setData(data: Object): void
  • public setData

    Sets the data for this asset.
    

    Parameters

    • data: Object

    Returns void

setLoadStrategy

  • public setLoadStrategy

    Sets the strategy class to be used for loading
    

    Parameters

    Returns void

setMaxListeners

  • setMaxListeners(n: number): this

setSource

  • setSource(source: string): void
  • public setSource

    Sets the source location path of this asset.
    This will clear the associated data, and set this asset in the
    NOT_LOADED state.
    

    Parameters

    • source: string

    Returns void

setState

unload

  • unload(): Promise<Asset>

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number

Generated using TypeDoc