Jump to content

setTexture doesn't always use preloaded images?


mrvinegar
 Share

Recommended Posts

I am loading individual texture images using "new PIXI.AssetLoader"

 

Then later when a user clicks on an image i am changing the image using:

 

"

var textureName = PIXI.Texture.fromImage ('images/img.png']);

this.setTexture(textureName);

"

 

However the "preloaded" image isn't always displaying, and needs to load again...

 

Am I doing something wrong?

 

Thanks

Link to comment
Share on other sites

`PIXI.Texture.fromImage ('images/img.png');` will load the image, but it is asynchronous, the image has to load.
 
Try this:



var tx = PIXI.Texture.fromImage ('images/img.png');if(tx.baseTexture.hasLoaded) {    //you can use the image immediately, it was cached} else {    //you have to wait for it to load    tx.on('update', function() {        //now you can use it    });}

If the image was preloaded, the first code block will execute (so if you are sure you preloaded you don't need this if-else block). If you are saying that you preloaded, but fromImage isn't working the way you use it above, I would need an example page because that is exactly how it should work (it should synchronously pull from the cache if preloaded).

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