omnivibe Posted January 6, 2015 Share Posted January 6, 2015 When using:var spr = new PIXI.Sprite.fromImage(itemURL);How can I get notified when the image is actually loaded, i.e. when spr.width and spr.height are available? Quote Link to comment Share on other sites More sharing options...
ceraroger Posted January 6, 2015 Share Posted January 6, 2015 I think you can add listener for 'loaded' event of the baseTexture.var spr = new PIXI.Sprite.fromImage(itemURL);spr.texture.baseTexture.on('loaded', function(){ console.log(spr.width, spr.height);}); Quote Link to comment Share on other sites More sharing options...
d13 Posted January 6, 2015 Share Posted January 6, 2015 Yes, it's possible to use `fromImage`, but it's not a good idea - for exactly the reason you've discovered.It's better to preload images with Pixi's `AssetLoader` and then initialize the sprites in a separate `setup` function.var loader = new PIXI.AssetLoader([ "images/imageOne.png", "images/imageTwo.png", "images/imageThree.png"]);loader.onComplete = setup;loader.load();function setup() { //Create the sprite from the loaded image texture var texture = PIXI.TextureCache["images/imageOne.png"]; var anySprite = new PIXI.Sprite(texture);} Quote Link to comment Share on other sites More sharing options...
JDW Posted January 6, 2015 Share Posted January 6, 2015 If you already loaded your images with an assetloader, you can use fromImage, it will retrive it from the cache, not reload it. That's one less line. 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.