I wanted to take screenshots of the screen using the internal functions of Gosu, but I'm having trouble using the record method. Here is the code I got after some trial and error, advised by ChatGPT.
require "gosu"
class App < Gosu::Window
def draw
draw_rect(0, 0, 32, 32, Gosu::Color::BLUE)
end
def button_down(id)
if id == Gosu::KB_SPACE
Gosu.record(width, height) { draw }.save("screenshot.png")
end
end
new(320, 240).show
end
However, when I run this and press space, I get the following error:
`save': Gosu::Graphics can only be drawn to while rendering (RuntimeError)
Is it possible that the record method is meant for generating its own new texture, and is not suitable for simply wanting a screenshot of the screen?
I wanted to take screenshots of the screen using the internal functions of Gosu, but I'm having trouble using the record method. Here is the code I got after some trial and error, advised by ChatGPT.
However, when I run this and press space, I get the following error:
Is it possible that the record method is meant for generating its own new texture, and is not suitable for simply wanting a screenshot of the screen?