Quantcast
Channel: Pixi.js Latest Topics
Viewing all articles
Browse latest Browse all 3978

Placeholder system

$
0
0

I am currently trying to implement a system where placeholder images can be displayed while the actual images are being loaded. I would like to ask for some examples that have already done this using PIXIjs.

Structure I came up with:

    export class ImageDefinition {
        placeholder: PIXI.Texture
        resource: PIXI.LoaderResource
        callbacks: ((texture: PIXI.Texture) => void)[] = []
        loaded: boolean = false

        GetTexture(callback: (texture: PIXI.Texture) => void): void {
            if(!this.resource.isComplete) {
                callback(this.placeholder)
                return
            }

            this.callbacks.push(callback)
        }

        // This function is called by the asset loader
        LoadCompleted() {
            // Run all callbacks here
        }
    }

How this would be used:

probabilityTexture.GetTexture((texture) => {
    // this code will be run twice, for placeholder and later for real image
});

What do you think about the system above?


Viewing all articles
Browse latest Browse all 3978

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>