Jump to content

Get the real width of an image


Dina
 Share

Recommended Posts

Hello PIXI community!

let image = PIXI.Sprite.from("imagePath");

I don't use loader for creating images and I pass this to a module where I need to get the real width of the image, but I get the width equal to 1 as I don't use loader (Hope I get this part right). So I used loader to get the real width but I got problems with passing the image to module as the image is used in setup function that is passed to loader. English is not my native language. Hope this makes sense))

 

So how do I create an image outside of the module and pass it to use it's width?

Link to comment
Share on other sites

When you're not using a preloader... the width is 1 until the image had been loaded. We can't know the true width of something if it's not been loaded yet. When it has, an event on the texture is fired and the true value can be known.

If using a loader, then it'll give you the references to things it loads which you can pass in elsewhere. The built in loader will add textures loaded into PIXI.utils.TextureCache that you can reference from anywhere. 

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