I’m messing around with embedding files and I am curious how do I get the assets that are embedded? Like, say I wanted to get an asset ./assets/background.png and the ./assets/ folder is embedded?
If I’m completely misinterpreting what embedding a file actually does, I’m sorry
in project.xml you add this to embed your images that are in assets/images folder <assets path="assets/images" include="*.png" embed="true" />
and in code it would be "assets/images/background.png"
also you can rename the path (an alias) you would use in code like this <assets path="assets/images" rename="img" include="*.png" embed="true" />
and in code it would be "img/background.png"
In the case of a windows build, when you embed the images, or other assets, they are embedded in the exe itself and no folders are in the build. For HTML5 the folders and files are included in the build, but you access them the same way.
I was more of meaning how do I actually access them because the file paths for the files aren’t actually there anymore. Using your example /img/background.png/ doesn’t work because that isn’t a valid path?
Using paths over id can be desirable when you have got tons of images and you don’t want to assign each one of them with an ID and also making the project.xml bulky and overwhelming.
The restricted syntax required to use the path (instead of id ) is what make it confusing most of the times. Often the confusion is about using “.” , “/” or both etc.
This won’t work even if the build has got the assets folder along with required images
<assets path="./assets" />
For example using
Assets.getBitmapData('assets/pic.png')));
will generate error
You must use rename attribute too.
<assets path="./assets" rename="assets" />
Assets.getBitmapData('assets/pic.png'))); //will work now
Also these too won’t work because of leading “.” and “/” or both
Assets.getBitmapData('assets/pic.png') // works
Assets.getBitmapData('./assets/pic.png') //ID not found error
Assets.getBitmapData('/assets/pic.png') //ID not found error