Hello,
I would like to scale sprites according to the size of the original image.
Example:
image 1 = (50px, 50px)
image 2= (100px,100px)
Then the sprite with the second image should be displayed twice as large.
However, I cannot find the original image size anywhere.
Is there a way to get the original image size for a sprite?
Thank you for your help!
To get the dimensions (in pixels) of the image in a sprite’s texture, try these:
sprite.material.map.image.height
sprite.material.map.image.width
or these
sprite.material.map.image.naturalHeight
sprite.material.map.image.naturalWidth
Note that sprite.material.map
is the texture used for the sprite and its image
property should be accessed only after the complete loading of the texture.
I tried it and it works
Your note was the essential information that I needed:
Note that sprite.material.map
is the texture used for the sprite and its image
property should be accessed only after the complete loading of the texture.
Thank you for the (very) quick response!