Capturing a portion of the screen with screenshot.html5 (SOLVED)

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.

What do you mean by ?

Can you share an sample image?

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)

Oh, it does? It could be for the HTML5 screenshot only. Could you please create an issue in the defold-screenshot GitHub repo?

Done! https://github.com/britzl/defold-screenshot/issues/7

2 Likes

I’ve updated the ticket with a fix available for testing it. I’d appreciate if you could give it a try as well. It worked for me at least.

3 Likes

I can confirm it works. Nice one!

2 Likes