Class: Ruby2D::Sound
- Inherits:
-
Object
- Object
- Ruby2D::Sound
- Defined in:
- lib/ruby2d/sound.rb,
ext/ruby2d/ruby2d-opal.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #ext_init(path) ⇒ Object
- #ext_play ⇒ Object
-
#initialize(path) ⇒ Sound
constructor
A new instance of Sound.
- #play ⇒ Object
Constructor Details
#initialize(path) ⇒ Sound
Returns a new instance of Sound.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby2d/sound.rb', line 9 def initialize(path) unless RUBY_ENGINE == 'opal' unless File.exists? path raise Error, "Cannot find audio file `#{path}`" end end @path = path ext_init(path) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/ruby2d/sound.rb', line 6 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/ruby2d/sound.rb', line 7 def path @path end |
Instance Method Details
#ext_init(path) ⇒ Object
227 228 229 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 227 def ext_init(path) `#{self}.data = S2D.CreateSound(path);` end |
#ext_play ⇒ Object
231 232 233 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 231 def ext_play `S2D.PlaySound(#{self}.data);` end |
#play ⇒ Object
21 22 23 |
# File 'lib/ruby2d/sound.rb', line 21 def play ext_play end |