Using the screenshot extension I want to the capture area to match the bounding box of a gui node. How would I achieve this? I’ve spent a few hours trying various things, with no luck (the capture works, but is in the wrong place):
Using gui.get_position()
Using gui.get_screen_position()
Converting the position with code from the posts below (code I’ve tested and am using in other parts of the game.
How can I capture the correct position and size of a node?
Edit: Drawing a debug line from the x,y works, it appears at the node anchor.
I figured it out; the y position was wrong because Defold’s coordinate system starts at the bottom, and the plugin starts from the top.
This did the trick:
local pos = gui.get_screen_position(node)
local size = gui.get_size(node)
local w = size.x
local h = size.y
local x = pos.x - (w/2)
local y = (screen_height-pos.y) - (h/2)
screenshot.html5( x,y,w,h, function(self, base64_img)
--
end)