I know it works, but I have no idea if it is the correct way to get the url, and can work all the time…
How can I refer the image correctly in CSS in playcanvas
Anyone can help plz?
Is there another way to set the correct url instead of finding it ?
For example, I put 1.png in the root dirctory like the second pic shows,
so the correct url might be
/1.png
In other words, I want the correct path about 1.png in my application
If you want to use asset URLs in CSS one way to do this is to write a special string for each URL instead of the actual URL and then in your code replace those strings with the actual asset URLs. E.g.
background: url([asset.tag]); (where tag is a tag you added to the asset in the Editor)
Then in your code find all strings that look like [asset.tag] and replace that with the asset that you get by getFileUrl()
Yes, this is what I’m doing now, but probably it is not really good.
The thing is, I put 1.png in the directory, and of couse I know where it is, but I don’t know what the correct relative path for it.
Because of this, my program got to find it and then set it when running .
If I know the correct relative path at the beginning and set it in the button CSS code, it will be much better.
The folder structure you see in the Editor is not the real structure of the assets. The only way to know the real URL of an asset no matter where your application is running from is to call asset.getFileUrl(), so the way you’re doing it is your best bet right now.
Hi - would I need to put the var assets and var images in to a ui.js file?
I’m attempting to do my UI with HTML & CSS and trying to use svg backgrounds in my css. I’ve got the HTML and CSS showing in my game debug URL, but I’m unclear where to place the var assets and var images code. Thanks so much for any info