I feel this is bug, let me explain my experience, after running the set_texture code in a dynamic script gui included in my texture_load function, the sample code for creating a box node won’t display a box.
If I try to create this box node before trying to set this textures I can see the box, I feel like there is some problem with HTML5 and setting dynamic textures, not something I need for my project, but tested it just to check.
function textures_load()
-- Load Chapter Image
local f = assert(io.open("assets/img.png", "rb"))
local data = assert(f:read("*a"))
img = image.load(data, true)
local type = (img.type == image.TYPE_RGB) and "rgb" or "rgba"
gui.new_texture("chapter_image", img.width, img.height, type, img.buffer, false)
-- Load Background Image
f = assert(io.open("assets/bk.png", "rb"))
data = assert(f:read("*a"))
img_bk = image.load(data, true)
type = (img_bk.type == image.TYPE_RGB) and "rgb" or "rgba"
gui.new_texture("back_image", img_bk.width, img_bk.height, type, img_bk.buffer, false)
end
function init(self)
-- Add initialization code here
-- Learn more: https://defold.com/manuals/script/
-- Remove this function if not needed
msg.post(".", "acquire_input_focus") -- <1>
self.state = "-"
textures_load()
-- Create a new box node
local new_position = vmath.vector3(400, 300, 0)
local new_size = vmath.vector3(450, 400, 0)
local new_boxnode = gui.new_box_node(new_position, new_size)
gui.set_color(new_boxnode, vmath.vector4(0.2, 0.26, 0.32, 1))