Jump to content

Size of texture is 0 when using snowpack dev


Vorlington
 Share

Recommended Posts

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 by Vorlington
Link to comment
Share on other sites

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 by Vorlington
Link to comment
Share on other sites

  • Vorlington changed the title to Size of texture is 0 when using snowpack dev

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