mrvinegar Posted December 16, 2013 Share Posted December 16, 2013 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 Quote Link to comment Share on other sites More sharing options...
xerver Posted December 16, 2013 Share Posted December 16, 2013 `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). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.