1

Im trying to get the width and height from the texture of a sprite. The properties should be available according to the documentation, and when when doing console.log(texture) they are correct, but when doing console.log(texture.height) it always returns 1. This is the code:

let texture = PIXI.Texture.fromImage(path);
    console.log(texture);
    console.log(texture.height);

console.log(texture) shows this:

...

_updateID:2
_uvs:t
frame:(...)
height:240
rotate:0
width:240

...

which is the correct width and height, but why can't i get the values?

gman
  • 100,619
  • 31
  • 269
  • 393
anton petersson
  • 143
  • 1
  • 1
  • 9

1 Answers1

3

I found out what the problem was. The texture probably didn't load properly before i tried to fetch the value. I used the PIXI loader object to preload all textures and it works perfect now.

anton petersson
  • 143
  • 1
  • 1
  • 9