Jambutters Posted October 4, 2016 Share Posted October 4, 2016 Quite a javascript newbie here so bare with me. So I'm not sure what the differences are between the two if any. So is it recommended to always reload images with loader rather than using fromImage? On a non related note: I get an uncaught type error : cannot set property 'frame' of undefined. When I remove the setup call from the bottom, the error message goes away but I'm not sure why. If it ran again, shouldn't there be no errors? Thanks let renderer = PIXI.autoDetectRenderer(416,416); let rootStage = new PIXI.Container(); document.body.appendChild(renderer.view); class Entity { constructor(img,id, type, hp, x, y, height, width, spdX, spdY){ this.img = img; this.id = id; this.type = type; //for players it this reffers to player class, monsters is different this.hp = hp; this.x = x; this.y = y; this.height = height; this.width = width; this.spdX = spdX; this.spdY = spdY; } attack() { console.log("aatt"); } } let gUpdate = () =>{ //setInterval(gUpdate, 1000/20); renderer.render(rootStage); }; let z; let setup = () =>{ let e = PIXI.utils.TextureCache[player.img]; let rectangle = new PIXI.Rectangle(0,0, 32,32); e.frame = rectangle; z = new PIXI.Sprite(e); //PIXI.loader.resources[player.img].texture rootStage.addChild(z); gUpdate(); } let player = new Entity("img/aa.png","p","pyro",100,0,0,32,32); PIXI.loader.add(player.img).load(setup); setup(); Quote Link to comment Share on other sites More sharing options...
xerver Posted October 4, 2016 Share Posted October 4, 2016 Dont do this: let e = PIXI.utils.TextureCache[player.img]; Instead use the resources the loader loaded for you: let e = PIXI.loader.resources[player.img].texture; The error you get is because `PIXI.utils.TextureCache[player.img]` doesn't exist, this is happening because you are calling setup manually: PIXI.loader.add(player.img).load(setup); setup(); You pass it in as a callback, then immediately invoke it manually. Don't do that, just pass it in as a callback and the loader will call it when loading has completed (asynchronously). Kraghen 1 Quote Link to comment Share on other sites More sharing options...
Jambutters Posted October 5, 2016 Author Share Posted October 5, 2016 11 hours ago, xerver said: Dont do this: let e = PIXI.utils.TextureCache[player.img]; Instead use the resources the loader loaded for you: let e = PIXI.loader.resources[player.img].texture; Ah I see. So its always best to use the texture in the loader? When would PIXI.utils.TextureCache be used? Kind of confused between the two, they both generally serve the same purpose . Quote Link to comment Share on other sites More sharing options...
xerver Posted October 5, 2016 Share Posted October 5, 2016 The texture cache is used to ensure that extra calls to .fromImage() don't make multiple browser requests. If you use the loader, use the loader. If you use the fromImage() methods, use those. Try not to mix them Quote Link to comment Share on other sites More sharing options...
Kraghen Posted May 24, 2019 Share Posted May 24, 2019 On 10/5/2016 at 4:19 AM, xerver said: The texture cache is used to ensure that extra calls to .fromImage() don't make multiple browser requests. If you use the loader, use the loader. If you use the fromImage() methods, use those. Try not to mix them How do I load cached images when using Loader.resources? When I load the app the second time i get warnings that the Texture already have en entry:"Texture added to the cache with an id [images/circle24.png] that already had an entry" I can see the image is already present in the texture Cahe, but when using Loader i would like to get the texture from Loader.resources, but that one is empty if i dont load the image again...? More on the case here: /thanks bbyford 1 Quote Link to comment Share on other sites More sharing options...
bbyford Posted August 17, 2020 Share Posted August 17, 2020 On 5/24/2019 at 12:43 PM, Kraghen said: How do I load cached images when using Loader.resources? When I load the app the second time i get warnings that the Texture already have en entry:"Texture added to the cache with an id [images/circle24.png] that already had an entry" I can see the image is already present in the texture Cahe, but when using Loader i would like to get the texture from Loader.resources, but that one is empty if i dont load the image again...? More on the case here: /thanks Having similar issues 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.