In 1.4.2 we got a new functionality with resource.create_atlas
using that in conjunction with resource.create_texture
and resource.set_texture
we can now create atlases at runtime.
It is a powerful feature that enables you to use files on disk (such as downloaded images) and set them into an atlas and then use these images in your collections. This is very useful if you download 100s of images and want to show them at the same time. As if you did that you would most likely run out of resources.
Over the last couple of days I have been trying this out and the outcome of this is this repository. It serves as both a example and a naive runtime texture packing solution.
Usage
It’s fairly straightforward to use the packing of the library. You only need to supply a name of the runtime atlas as well as the images you want to pack, and of course width and height.
local atlas_entries = {
"example/assets/images/image0.png", "example/assets/images/image1.png"
}
local atlas_id = rtatlas.pack("example", atlas_entries, 256, 256)
go.set("#sprite", "image", atlas_id)
sprite.play_flipbook("#sprite", "image0.png")
I have to admit that I struggled with figuring this feature out as there was a lot of things about packing atlases I wasn’t aware of, I would recommend to you to look into the code of runtime-atlas/runtime-atlas.lua
if you struggle with it too, I have added a lot of comments to the code to help you understand it more.