anton petersson
anton petersson

Reputation: 163

Pixi.Texture, get height and width

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?

Upvotes: 1

Views: 2937

Answers (1)

anton petersson
anton petersson

Reputation: 163

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.

Upvotes: 5

Related Questions