I have tried with both the built-in image.load
and with with GitHub - britzl/defold-png: Defold native extension to load and save PNG images, but both yield an error about trying to index nil
- either image
isn’t defined or png
isn’t defined, so their various methods aren’t available.
I guess theoretically I could use a separate tool, like a go binary or something I could build and embed in the project to read png files, but that seems a bit superfluous to do in a system that obviously reads png files as resources internally.
Example:
local function read_tile_image(file_path)
local file = io.open(file_path, "rb")
if not file then
error("can't load tilemap image:", file_path)
end
local bytes = file:read("*a")
-- @TODO: apparently editor scripts can't do this?
-- local img = image.load_buffer(bytes)
-- if not img then
-- error("can't load tilemap image:", file_path)
-- end
-- return img
-- @TODO: this also doesn't work in an editor script:
-- local buffer, width, height = png.decode_rgba(bytes, true)
-- local pixels = buffer.get_stream(buffer, hash("pixels"))
-- return { pixels, width, height }
end