Jump to content

Placeholder system


sussyboi
 Share

Recommended Posts

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...