pnvvma
Last Updated: February 25, 2016
·
804
· tjbladez

Ruby Gosu Window Management Via Delegates

There are reasons why you can't just switch windows in gosu. You have to use single Window object and delegates

class Window < Gosu::Window
  def initialize(name)
    super(1024, 768, false)
    set_delegate(name)
  end

  def draw
    @delegate.draw
  end

  def update
    @delegate.update
  end

  def set_delegate(name, opts={})
    @delegate = Object.const_get(name).new(self, opts)
  end

  def method_missing(sym, *args, &block)
    @delegate.send(sym, *args, &block)
  end
end