Events

Published: September 03, 2019
Edited: December 08, 2020

Here's a list of loading events fired by a texture:

NameDescription
txLoadedfires when a texture is successfully loaded
txErrorfires when there's an error loading a texture
txUnloadedfires when a texture is unloaded

Example:

shows a placeholder image when the first one doesn't load:


class TextureEventsExample extends lng.Application {
    static _template() {
        return {
            Image: {
                x: 20,
                y: 20,
                alpha: 0.01,
                src: '/invalid/path.png'
            }
        }
    }

    _init() {
        this.tag('Image').on('txLoaded', () => {
            console.log('texture loaded: ' + this.tag('Image').src)
            this.tag('Image').setSmooth('alpha', 1)
        })

        this.tag('Image').on('txError', () => {
            console.error('texture failed to load: ' + this.tag('Image').src)
            this.showPlaceholder()
        })
    }

    showPlaceholder() {
        this.tag('Image').src = '/Lightning/img/LngDocs_LilLightningIdle.png'
    }
}

const options = {stage: {w: window.innerWidth, h: window.innerHeight, useImageWorker: false}};
const app = new TextureEventsExample(options);
document.body.appendChild(app.stage.getCanvas());
PHP Code Snippets Powered By : XYZScripts.com