Vorlington Posted February 17, 2023 Share Posted February 17, 2023 (edited) Hello! I'm porting code from PIXI 4 to PIXI 7 and I'm stuck with some runtime errors. After digging into, it seems to be a problem with the size of a texture. I came up with this little reproducer: import * as PIXI from 'pixi.js'; document.addEventListener("DOMContentLoaded", function() { const app = new PIXI.Application({ background: '#1099bb' }); document.body.appendChild(app.view as HTMLCanvasElement); PIXI.Assets.load('/Images/engine/check.png').then(() => { const baseTexture = PIXI.BaseTexture.from('Images/engine/check.png'); console.log(baseTexture.width + " " + baseTexture.height + " " + baseTexture.valid); const texture = new PIXI.Texture(baseTexture, new PIXI.Rectangle(0, 0, baseTexture.width/2, baseTexture.height/2)); const sprite = new PIXI.Sprite(texture); app.stage.addChild(sprite); }); }); Nothing is displayed because the size of baseTexture seems to be zero. (it displays "0, 0, false" in console). It worked with PIXI 4 a priori. Strangely, when I display baseTexture with console.log(baseTexture), the size is not zero. The google searches often talk about a texture that is not loaded. However it seems to me that it is with PIXI.Assets.load... Isn't this how it's supposed to work? I must be missing something but I can't see what. If someone can enlighten me that would be cool! PS I don't know if it's related, but I'm with node.js and snowpack. With PIXI 4 it was without node. Edited February 20, 2023 by Vorlington Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 17, 2023 Share Posted February 17, 2023 (edited) one is with slash, another is without, maybe? specify base path for Assets (i dont know how to ) , use "engine/check.png" in both then ? Edited February 17, 2023 by ivan.popelyshev Quote Link to comment Share on other sites More sharing options...
Vorlington Posted February 17, 2023 Author Share Posted February 17, 2023 (edited) Thanks ivan for the reply. But the slash does not change anything. Actually I have tested with different images and several ways to load it : with bundle, with PIXI.Assets.add and a key, with await instead of .then() etc. I can also see that the image is loaded in the network tools (and is not if I do a typo in the name). If I use one of the two following lines, it works well of course : const texture = PIXI.Texture.from('Images/engine/check.png'); const texture = new PIXI.Texture(baseTexture, new PIXI.Rectangle(0, 0, 128, 128)); btw, it seems that you can set a base path for the Assets loader with PIXI.Assets.resolver.basePath = 'Images/'; But you need the complete path in PIXI.BaseTexture.from() (?) and unfortunately, it does not change anything for my problem. Edited February 17, 2023 by Vorlington Quote Link to comment Share on other sites More sharing options...
Vorlington Posted February 20, 2023 Author Share Posted February 20, 2023 (edited) Hello ! I made some progress today: If I embed the script and pixi directly into the web page, without node, it works ! So I tested with webpack instead of snowpack and... it works! And finally, I just builded with "snowpack build" and launched a web server on the result and it works. So it's only with snbowpack dev that it doesn't work. I'm not expert enough in snowpack to go any further. I will update the title to indicate that the problem is snowpack related. Strange though... Edited February 21, 2023 by Vorlington 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.