Class/Module Index [+]

Quicksearch

Rubygame

Ftor ("Fake vecTOR"), a vector-like class for 2D position/movement.


Hotspot, a mixin module to extend an object with custom, named, relative position offsets.


Common / utility methods.

Constants

ACTIVEEVENT
ANYFORMAT
ASYNCBLIT
DOUBLEBUF
FULLSCREEN
HAT_CENTERED

Joystick constants

HAT_DOWN
HAT_LEFT
HAT_LEFTDOWN
HAT_LEFTUP
HAT_RIGHT
HAT_RIGHTDOWN
HAT_RIGHTUP
HAT_UP
HWACCEL
HWPALETTE
HWSURFACE
JOYAXISMOTION
JOYBALLMOTION
JOYBUTTONDOWN
JOYBUTTONUP
JOYHATMOTION
KEYDOWN
KEYUP
K_0
K_1
K_2
K_3
K_4
K_5
K_6
K_7
K_8
K_9
K_A
K_AMPERSAND
K_ASTERISK
K_AT
K_B
K_BACKQUOTE
K_BACKSLASH
K_BACKSPACE
K_BREAK
K_C
K_CAPSLOCK
K_CARET
K_CLEAR
K_COLON
K_COMMA
K_D
K_DELETE
K_DOLLAR
K_DOWN
K_E
K_END
K_EQUALS
K_ESCAPE
K_EURO
K_EXCLAIM
K_F
K_F1

Function keys

K_F10
K_F11
K_F12
K_F13
K_F14
K_F15
K_F2
K_F3
K_F4
K_F5
K_F6
K_F7
K_F8
K_F9
K_FIRST
K_G
K_GREATER
K_H
K_HASH
K_HELP

Miscellaneous keys

K_HOME
K_I
K_INSERT
K_J
K_K
K_KP0

Numeric keypad symbols

K_KP1
K_KP2
K_KP3
K_KP4
K_KP5
K_KP6
K_KP7
K_KP8
K_KP9
K_KP_DIVIDE
K_KP_ENTER
K_KP_EQUALS
K_KP_MINUS
K_KP_MULTIPLY
K_KP_PERIOD
K_KP_PLUS
K_L
K_LALT
K_LAST
K_LCTRL
K_LEFT
K_LEFTBRACKET
K_LEFTPAREN
K_LESS
K_LMETA
K_LSHIFT
K_LSUPER
K_M
K_MENU
K_MINUS
K_MODE
K_N
K_NUMLOCK

Key state modifier keys

K_O
K_P
K_PAGEDOWN
K_PAGEUP
K_PAUSE
K_PERIOD
K_PLUS
K_POWER
K_PRINT
K_Q
K_QUESTION
K_QUOTE
K_QUOTEDBL
K_R
K_RALT
K_RCTRL
K_RETURN
K_RIGHT
K_RIGHTBRACKET
K_RIGHTPAREN
K_RMETA
K_RSHIFT
K_RSUPER
K_S
K_SCROLLOCK
K_SEMICOLON
K_SLASH
K_SPACE
K_SYSREQ
K_T
K_TAB
K_U
K_UNDERSCORE
K_UNKNOWN

ASCII key symbols

K_UP

Arrows + Home/End pad

K_V
K_W
K_WORLD_0

International keyboard symbols

K_WORLD_1
K_WORLD_10
K_WORLD_11
K_WORLD_12
K_WORLD_13
K_WORLD_14
K_WORLD_15
K_WORLD_16
K_WORLD_17
K_WORLD_18
K_WORLD_19
K_WORLD_2
K_WORLD_20
K_WORLD_21
K_WORLD_22
K_WORLD_23
K_WORLD_24
K_WORLD_25
K_WORLD_26
K_WORLD_27
K_WORLD_28
K_WORLD_29
K_WORLD_3
K_WORLD_30
K_WORLD_31
K_WORLD_32
K_WORLD_33
K_WORLD_34
K_WORLD_35
K_WORLD_36
K_WORLD_37
K_WORLD_38
K_WORLD_39
K_WORLD_4
K_WORLD_40
K_WORLD_41
K_WORLD_42
K_WORLD_43
K_WORLD_44
K_WORLD_45
K_WORLD_46
K_WORLD_47
K_WORLD_48
K_WORLD_49
K_WORLD_5
K_WORLD_50
K_WORLD_51
K_WORLD_52
K_WORLD_53
K_WORLD_54
K_WORLD_55
K_WORLD_56
K_WORLD_57
K_WORLD_58
K_WORLD_59
K_WORLD_6
K_WORLD_60
K_WORLD_61
K_WORLD_62
K_WORLD_63
K_WORLD_64
K_WORLD_65
K_WORLD_66
K_WORLD_67
K_WORLD_68
K_WORLD_69
K_WORLD_7
K_WORLD_70
K_WORLD_71
K_WORLD_72
K_WORLD_73
K_WORLD_74
K_WORLD_75
K_WORLD_76
K_WORLD_77
K_WORLD_78
K_WORLD_79
K_WORLD_8
K_WORLD_80
K_WORLD_81
K_WORLD_82
K_WORLD_83
K_WORLD_84
K_WORLD_85
K_WORLD_86
K_WORLD_87
K_WORLD_88
K_WORLD_89
K_WORLD_9
K_WORLD_90
K_WORLD_91
K_WORLD_92
K_WORLD_93
K_WORLD_94
K_WORLD_95
K_X
K_Y
K_Z
MOUSEBUTTONDOWN
MOUSEBUTTONUP
MOUSEMOTION
MOUSE_LEFT

Mouse constants

MOUSE_LMASK
MOUSE_MIDDLE
MOUSE_MMASK
MOUSE_RIGHT
MOUSE_RMASK
NOEVENT

Event constants

NOFRAME
OPENGL
OPENGLBLIT
PREALLOC
QUIT
RESIZABLE
RLEACCEL
RLEACCELOK
SDL_EVENTS

List of all Rubygame hardware event classes. *Do not modify!*

SRCALPHA
SRCCOLORKEY
SWSURFACE
SYSWMEVENT
USEREVENT
VERSIONS
VIDEOEXPOSE
VIDEORESIZE

Public Class Methods

audio_driver() click to toggle source

Returns the name of the audio driver that SDL is using. This method opens the audio device if it is not open already.

May raise an SDLError if the audio device could not be opened.

# File lib/rubygame/audio.rb, line 142
def self.audio_driver
  open_audio
  return SDL.AudioDriverName
end
close_audio() click to toggle source

Deinitializes and closes the audio device. If audio was not open, this method does nothing, and returns false. See also open_audio().

NOTE: The audio will be automatically closed when the program exits. You only need to close audio manually if you want to call open_audio with different settings.

Returns

true if the audio was open before this action.

# File lib/rubygame/audio.rb, line 122
def self.close_audio
  if audio_open?
    SDL::Mixer.CloseAudio()
    return true
  else
    return false
  end
end
disable_key_repeat() click to toggle source

Disable key repeat, undoing the effect of enable_key_repeat.

# File lib/rubygame/events.rb, line 74
def self.disable_key_repeat
  result = SDL.EnableKeyRepeat( 0, 0 )

  if result != 0
    raise( Rubygame::SDLError,
           "Could not disable key repeat: #{SDL.GetError()}" )
  end

  return nil
end
enable_key_repeat( delay=:default, interval=:default ) click to toggle source

Enable key repeat, so that additional keyboard release and press events are automatically generated for as long as the key is held down. See also disable_key_repeat.

delay

how many seconds to wait before starting to repeat. Default is 0.5 seconds. (Numeric or :default, optional)

interval

how many seconds to wait in between repetitions after the first one. Default is 0.03 seconds. (Numeric or :default, optional)

# File lib/rubygame/events.rb, line 37
def self.enable_key_repeat( delay=:default, interval=:default )

  delay = if delay == :default
            SDL::DEFAULT_REPEAT_DELAY
          else
            delay.to_f
          end

  interval = if interval == :default
               SDL::DEFAULT_REPEAT_INTERVAL
             else
               interval.to_f
             end

  if delay < 0.001
    raise( ArgumentError,
           "delay must be at least 0.001 sec (got #{delay})" )
  end

  if interval < 0.001
    raise( ArgumentError,
           "interval must be at least 0.001 sec (got #{interval})" )
  end

  result = SDL.EnableKeyRepeat( (delay * 1000).to_i, (interval * 1000).to_i )

  if result != 0
    raise( Rubygame::SDLError,
           "Could not enable key repeat: #{SDL.GetError()}" )
  end

  return nil
end
fetch_sdl_events() click to toggle source

Retrieves all pending events from SDL's event stack and converts them into Rubygame Event objects. Returns an Array of all the events, in the order they were read.

This method is used by the EventQueue class, so don't call it if you are using EventQueue for event management! If you do, the EventQueue will not receive all the events, because they will have been removed from SDL's event stack by this method.

However, if you aren't using EventQueue, you can safely use this method to make your own event management system.

# File lib/rubygame/event.rb, line 36
def fetch_sdl_events
  deprecated("Rubygame.fetch_sdl_events", "3.0")
  events = []
  until( ( event = SDL::PollEvent() ).nil? )
    events << _convert_sdlevent(event)
  end
  return events
end
init() click to toggle source

Initialize Rubygame. This should be called soon after you require Rubygame, so that everything will work properly.

# File lib/rubygame/main.rb, line 36
def self.init
  if( SDL.Init(SDL::INIT_EVERYTHING) == 0 )
    SDL.EnableUNICODE(1)
  else
    raise Rubygame::SDLError, "Could not initialize SDL: #{SDL.GetError()}"
  end
end
key2str( sym, mods ) click to toggle source

Converts a keyboard symbol (keysym) into a human-readable text string. If either Shift key was being pressed, alphanumeric or punctuation keys will be made uppercase or alternate, based on U.S. keyboard layout. E.g. "a" becomes "A", "1" becomes "!", and "/" becomes "?".

# File lib/rubygame/event.rb, line 140
def Rubygame.key2str( sym, mods )
        if (mods.include? K_LSHIFT) or (mods.include? K_RSHIFT)
                return (Rubygame::Key::KEY2UPPER[sym]                                 or Rubygame::Key::KEY2ASCII[sym] or "")
        else
                return (Rubygame::Key::KEY2LOWER[sym]                                 or Rubygame::Key::KEY2ASCII[sym] or "")
        end
end
open_audio( options={:buffer=>1024, :channels=>2, :frequency=>22050} ) click to toggle source

Initializes the audio device using the given settings.

NOTE: Audio will be automatically opened when Rubygame::Sound or Rubygame::Music are first used. You only need to open audio manually if you want settings different from the default, or if you are using the older, deprecated Music and Sample classes from the Rubygame::Mixer module.

If audio is already open, this method has no effect, and returns false. If you want to change audio settings, you must close_audio() and then open it again.

options

A Hash of any of the following options. (Hash, optional)

:frequency

output sample rate in audio samples per second (Hz). Affects the quality of the sound output, at the expense of CPU usage. If omitted, the default (22050) is used. The default is recommended for most games.

:channels

output sound channels. Use 2 for stereo, 1 for mono. If omitted, the default (2) is used.

:buffer

size of the sound buffer, in bytes. Must be a power of 2 (e.g. 512, 1024, 2048). If omitted, the default (1024) is used. If your game is fast-paced, you may want to use a smaller value to reduce audio delay, the time between when you play a sound and when it is heard.

Returns

true if the audio was newly opened by this action, or false if it was already open before this action.

May raise

SDLError, if initialization fails. ArgumentError, if an invalid value is given for any option.

# File lib/rubygame/audio.rb, line 63
def self.open_audio( options={} )
  return false if audio_open?

  unless options.kind_of? Hash
    raise TypeError, "invalid options Hash: #{options.inspect}"
  end

  buff = (options[:buffer] or 1024)
  chan = (options[:channels] or 2)
  freq = (options[:frequency] or SDL::Mixer::DEFAULT_FREQUENCY)

  # In general, format should always be the default.
  frmt = SDL::Mixer::DEFAULT_FORMAT


  buff = if( buff <= 0 )
           raise ArgumentError, "buffer size must be positive (got #{buff})"
         elsif( buff & (buff - 1) != 0 )
           raise( ArgumentError, "buffer size must be a power of 2 "+
                  "(e.g. 512, 1024) (got #{buff})" )
         else
           buff.to_i
         end


  chan = if( chan != 1 && chan != 2 )
           raise( ArgumentError, 
                  "channels must be 1 (mono) or 2 (stereo) (got #{chan})" )
         else
           chan.to_i
         end


  freq = if( freq <= 0 )
           raise ArgumentError, "frequency must be positive (got #{freq})"
         else
           freq.to_i
         end

  result = SDL::Mixer.OpenAudio(freq, frmt, chan, buff)

  if( result < 0 )
    raise Rubygame::SDLError, "Could not open audio: #{SDL.GetError()}"
  end

  return true
end
quit() click to toggle source

Quit Rubygame. This should be used before your program terminates, especially if you have been using a fullscreen Screen! (Otherwise, the desktop resolution might not revert to its previous setting on some platforms, and your users will be frustrated and confused!)

# File lib/rubygame/main.rb, line 50
def self.quit
  SDL.Quit
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.