Module: DXRubySDL::Window

Defined in:
lib/dxruby_sdl/window.rb,
lib/dxruby_sdl/window/fpstimer.rb

Defined Under Namespace

Classes: FPSTimer

Class Method Summary collapse

Class Method Details

._screenObject



9
10
11
12
13
14
# File 'lib/dxruby_sdl/window.rb', line 9

def _screen
  return SDL::Screen.get
rescue SDL::Error
  return SDL::Screen.open(DEFAULTS[:width], DEFAULTS[:height], 16,
                          SDL::SWSURFACE)
end

.draw(x, y, image, z = 0) ⇒ Object



39
40
41
# File 'lib/dxruby_sdl/window.rb', line 39

def draw(x, y, image, z = 0)
  _screen.put(image._surface, x, y)
end

.draw_font(x, y, string, font, hash = {}) ⇒ Object Also known as: drawFont



43
44
45
46
47
48
49
50
# File 'lib/dxruby_sdl/window.rb', line 43

def draw_font(x, y, string, font, hash = {})
  if hash[:color]
    r, g, b = *hash[:color]
  else
    r, g, b = 255, 255, 255
  end
  font._ttf.draw_blended_utf8(_screen, string, x, y, r, g, b)
end

.loop(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dxruby_sdl/window.rb', line 16

def loop(&block)
  timer = FPSTimer.instance
  timer.reset

  Kernel.loop do
    timer.wait_frame do
      while (event = SDL::Event.poll)
        case event
        when SDL::Event::Quit
          exit
        end
      end

      _screen.fill_rect(0, 0, DEFAULTS[:width], DEFAULTS[:height],
                        DEFAULTS[:background_color])

      yield

      _screen.update_rect(0, 0, 0, 0)
    end
  end
end