Class: Sound
- Inherits:
-
Object
- Object
- Sound
- Defined in:
- src/ruby/models/sound.rb,
mrb_doc/models/sound.rb
Overview
The Sound class holds shorter sounds, these are usually used for sound effects.
Defined Under Namespace
Classes: NotFound
Instance Attribute Summary collapse
Class Method Summary collapse
-
.load(path) ⇒ Sound
Loads a sound file from the specified path.
Instance Method Summary collapse
-
#initialize(frame_count) ⇒ Sound
constructor
Creates a new instance of Sound.
-
#pause ⇒ nil
Pauses the sound, you will need to call Sound#resume to start it again.
-
#play ⇒ nil
Starts playing the sound.
-
#playing? ⇒ Boolean
Is the sound currently playing?.
-
#resume ⇒ nil
Resumes the sound.
-
#stop ⇒ nil
Stops the sound, you will need to call Sound#play to start it again.
-
#to_h ⇒ Hash
Return the object represented by a Hash.
-
#unload ⇒ nil
Unloads the sound from memory.
Constructor Details
Instance Attribute Details
#frame_count ⇒ Integer
4 5 6 |
# File 'src/ruby/models/sound.rb', line 4 def frame_count @frame_count end |
#pitch ⇒ Float
7 8 9 |
# File 'src/ruby/models/sound.rb', line 7 def pitch @pitch end |
#volume ⇒ Float
7 8 9 |
# File 'src/ruby/models/sound.rb', line 7 def volume @volume end |
Class Method Details
.load(path) ⇒ Sound
Loads a sound file from the specified path
21 22 23 24 25 26 27 |
# File 'src/ruby/models/sound.rb', line 21 def self.load(path) raise Sound::NotFound.new("Could not find file at path \"#{path}\"") unless File.exist?(path) load_sound(path).tap { |sound| sound.volume = 1 sound.pitch = 1 } end |
Instance Method Details
#pause ⇒ nil
Pauses the sound, you will need to call Sound#resume to start it again
49 50 51 |
# File 'src/ruby/models/sound.rb', line 49 def pause pause_sound(self) end |
#play ⇒ nil
Starts playing the sound
37 38 39 |
# File 'src/ruby/models/sound.rb', line 37 def play play_sound(self) end |
#playing? ⇒ Boolean
Is the sound currently playing?
61 62 63 |
# File 'src/ruby/models/sound.rb', line 61 def (self) end |
#resume ⇒ nil
Resumes the sound
55 56 57 |
# File 'src/ruby/models/sound.rb', line 55 def resume resume_sound(self) end |
#stop ⇒ nil
Stops the sound, you will need to call Sound#play to start it again.
43 44 45 |
# File 'src/ruby/models/sound.rb', line 43 def stop stop_sound(self) end |
#to_h ⇒ Hash
Return the object represented by a Hash
11 12 13 14 15 |
# File 'src/ruby/models/sound.rb', line 11 def to_h { frame_count: frame_count, } end |
#unload ⇒ nil
Unloads the sound from memory
31 32 33 |
# File 'src/ruby/models/sound.rb', line 31 def unload unload_sound(self) end |