Home Reference Source Repository
import Assets from 'webgame-lib/src/assets.js'
public class | source

Assets

Loads required assets.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Initializes but does not load.

Member Summary

Public Members
public

Maps JSON paths to data.

public

images: Map<string, CanvasImageSource>

Maps image names to images.

public

prefix: *

Method Summary

Public Methods
public

load(manifest: Object): Promise

Loads all the assets specified in the manifest.

Public Constructors

public constructor(options: Object) source

Initializes but does not load.

Params:

NameTypeAttributeDescription
options Object
options.prefix string

Path prefix for all assets

options.smoothImage boolean

Whether scaled images use pixel interpolation

Public Members

public data: Map<string, Object> source

Maps JSON paths to data.

public images: Map<string, CanvasImageSource> source

Maps image names to images.

public prefix: * source

Public Methods

public load(manifest: Object): Promise source

Loads all the assets specified in the manifest.

Params:

NameTypeAttributeDescription
manifest Object

Manifest of assets to load

Return:

Promise

Promise that is fulfilled when the assets are loaded

Example:

let manifest = {
  images: {
    'imgs/all.png': {
      'img-1': {
        x: 0,
        y: 0,
        w: 16,
        h: 16,
        scale: 1
      }
    }
  },
  data: ['data/level.json']
}