How to obtain the URL of sprite in the project?

I have used this method in previous projects to obtain the URL of a png image and use it in HTML. This method is feasible, but as my project becomes more complex, there will be more and more images, resulting in a large number of requests. I understand that using sprite can reduce the number of requests, but I am not sure how to obtain the URL of sprite

I got sprite, but getFileUrl doesn’t seem to work

Hi @leooooooo,

A sprite isn’t an image file although it may render like that. A sprite asset contains coordinates to render part or the full image included in a texture atlas.

So using getFileUrl() will not return an image url as you expect. You should do that to the original texture atlas asset and it will work there.

Can it still obtain the sprites generated from the original texture atlas asset by using getFileUrl()?Is there a way to apply sprite to IMG tags in HTML?

No, you can’t use them in HTML, sprites are being consumed by a special shader to render part of the image on the WebGL canvas.

Okay, I understand. Thank you for your answer :grinning:

1 Like