Home Reference Source
import {Loader} from 'penvas/src/loader.js'
public class | source

Loader

Extends:

EventEmitter → Loader

Service to load asset

Example:

let layer = {
    create: function() {
        loader.add('img/my-image.png', 'player-image');
        loader.add('config/my-config.json', 'player-config', 'json');
    },
    render: function() {
         const image = loader.get('player-image');
         const config = loader.get('player-config');
         this.ctx.drawImage(image, config.x, config.y);
    }
}

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public
public
public
public
public

Method Summary

Public Methods
public

add(src: string, id: string, type: string)

Add asset to load

public

get(id: string): mixed

Get asset by id

public

load(el: mixed, id: string)

Add asset into the collection and dispatch event

Inherited Summary

From class EventEmitter
protected

List of registers

public

dispatch(event: String, args: mixed)

Dispatch event

public

on(event: String, callback: function, context: mixed)

Listen event

Public Constructors

public constructor() source

Override:

EventEmitter#constructor

Public Members

public collection: Array source

public count: number source

public progress: number source

public queue: number source

public ready: boolean source

Public Methods

public add(src: string, id: string, type: string) source

Add asset to load

Params:

NameTypeAttributeDescription
src string
id string
type string

(image or json)

public get(id: string): mixed source

Get asset by id

Params:

NameTypeAttributeDescription
id string

Return:

mixed

public load(el: mixed, id: string) source

Add asset into the collection and dispatch event

Params:

NameTypeAttributeDescription
el mixed
id string

Emit:

load

emit when asset is loaded

ready

emit when all assets are loaded