Jump to content

Check that PIXI.Texture is ready


charlie_says
 Share

Recommended Posts

Apologies this question feels a little basic:

I'm creating a Texture from data, which works fine - but there's a delay in the texture being ready. I've worked around this for now by using a timeout, Is there a way to use Promises to capture this (I've looked at some examples but it wasn't clear how.)

Thanks,

Charlie

Link to comment
Share on other sites

Actually, that's not enough.

Either you use promise form: https://www.pixiplayground.com/#/edit/dx4cOOhJ82M9b9P4thJ6o

Quote

const promise = PIXI.Texture.fromURL("https://i.imgur.com/jXMsFla.png");

promise.then((resolvedTexture) => {
    // or you can create sprite here based on resolvedTexture
    app.renderer.render(sprite, renderTexture);
})

 

either you use old one:

const doStuff = () = > {
    console.log('loaded');
}

if (texture.valid) {
    doStuff();
} else {
    texture.on('update', doStuff);
}

Internally, both are the same. If you open Sprite sources , onTextureUpdate method - that's exactly what will you see there.

Even if you are loading this texture first time, it can be ready just after from() method because it can be in browser cache

Edited by ivan.popelyshev
Link to comment
Share on other sites

Thanks @ivan.popelyshev I'd actually gone with this

	this._texture.on('update', () => { if (this._texture.valid) { this.contOpen()} });

which I think is more or less the same as yours. The only thing to note is that with mine this.contOpen() gets called twice.

I'm going to try your Promise example in the morning.

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...