Skip to content

[Question] Isn't Gosu.record intended for taking screenshots? #672

@akicho8

Description

@akicho8

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?

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions