I have a GUI with an atlas as texture. The atlas contains only images and no animations. When I create the GUI in the editor I can choose all images in the atlas as texture without problems.
Now I want to change which image from the atlas is used during runtime, but neither gui.set_texture nor gui.play_flipbook seems to work. I could of course create animations of single frames - but since I do not have to do that when I use the editor it seems to me I shouldn’t need to.
You need to to both. First:
gui.set_texture(node, "atlas")
and then
gui.play_flipbook(node, "texture")
Even if the image is in the same texture?
Edit: The same texture as the one I am changing from that is…
No, if you have set the atlas/tilesource (either in the editor or with gui.set_texture()) you can reference all animations in the atlas /tilesource with gui.play_flipbook(). You don’t have to set texture to change animation within the atlas/tilesource.
Ok, then I guess I am back at my question: Can I set an image in an atlas instead of an animation from code as I can in the editor - and in that case how?
Yes. Any image you add to an atlas become a 1 frame animation. Just use gui.play_flipbook().
So if you set the texture for node "box " in the editor to “my_atlas/picture” (“picture” is the 1 frame animation name for “picture.png”) then that corresponds to:
local n = gui.get_node("box")
gui.set_texture(n, "my_atlas")
gui.play_flipbook(n, "picture")
Ok, this is the second time I try something the way I think it works, it doesn’t work, ask a question here where you answer is it works as I think and when I retry it it works. Sorry for the timewasting…
No worries!! It’s very easy to miss some detail. I do that all the time.