Live update and GUI textures (SOLVED)

My game has around 100 bitmaps to be used in one GUI by setting the flipbook animation at runtime. Each bitmap needs to be loaded/unloaded on demand in an arbitrary order. What’s the best way of achieving this?

Adding textures at runtime is not possible, right?

Read the file from a file path, load it into a buffer use the buffer to load an image with and create a new texture from that.

local file = io.open(file_path, "rb")
local buffer = file:read("*all")
file:close()
local img = image.load(buffer, true)
gui.new_texture("some_unique_name", img.width, img.height, img.type, img.buffer, false)
1 Like

I was considering that too, and maybe it’s the only option? What if I needed to load, say, spine models or other more dynamic objects. Would that be possible to do in a dynamic way?

I can not think of a way to load a arbitrary spine file from disk. Maybe that could be solved by using the official spine-lua runtime, I bet it would be a herculean effort to get that to work though. Disclaimer: My knowledge of the official spine-lua runtime extends as far as that I know it exists.

What is your user case? To only go on “Each bitmap needs to be loaded/unloaded on demand in an arbitrary order” is a bit thin. Are they already on disk? In your project? Are you downloading the? Will you know things about the resources before you download?

1 Like

So, the Spine thing is something that might be added in the future, but having read your response, maybe not. :slight_smile: It’s a Facebook Instant game that needs to be light, even if a lot of content is added.

Yes, they are on disk and everything is known about them.

If they are already on disk then it is loading it you are concerned about? If you want the game to load fast then simply using Defold features such as “Load Dynamically” on factories, being smart with your atlas management, not over doing it on fonts and so on should take you a long way :slight_smile:

1 Like

Yes, it’s only the loading I’m trying to reduce. It loads pretty snappily now actually, mainly because everything is loaded dynamically - apart from these pesky bitmaps. I think the best (only?) route is your suggestion of loading/unloading the textures individually. Thanks for helping!

1 Like

You can place every image in a factory gameobject and mark it as “Load dynamically”.
For textures you can use my imageloader extension, which works faster for gameobjects than image.load() for gui.
However you’d have to convert your game to game objects instead of gui.

Regrettably this is not an option; the game is ideal for GUI rather than game objects, and it’s nearly feature complete.

I’m wondering how games with a lot of dynamic GUI object deal with this? Maybe they use game objects instead, as you suggest.

I get this error when using gui.new_texture(). Any idea what -6 means?

WARNING:GUI: Failed to create dynamic gui texture (-6)

Edit: Found the answer here. Error -6 means that the texture id is not unique.

1 Like
-6 = RESULT_TEXTURE_ALREADY_EXISTS

I’ll add some better log errors for this

3 Likes