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.
Joystick constants
Function keys
Miscellaneous keys
Numeric keypad symbols
Key state modifier keys
ASCII key symbols
Arrows + Home/End pad
International keyboard symbols
Mouse constants
Event constants
List of all Rubygame hardware event classes. *Do not modify!*
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
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, 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, 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
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
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
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
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 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
Generated with the Darkfish Rdoc Generator 2.