Module: SFML::Listener
- Defined in:
- lib/sfml/audio/listener.rb
Overview
The “ear” — a global, single-instance object that defines from where the player hears the world. Sounds positioned via Sound#position= attenuate based on their distance from this point.
SFML::Listener.position = [400, 300, 0] # follow your camera
SFML::Listener.global_volume = 80 # 0..100, master gain
For 2D games keep z = 0 and treat x, y as world coords. For first-person stuff also set Listener.direction to point along the camera forward.
Class Method Summary collapse
-
.direction ⇒ Object
The forward direction of the listener (unit-length, doesn’t have to be).
- .direction=(value) ⇒ Object
-
.global_volume ⇒ Object
Master volume in the range [0, 100].
- .global_volume=(value) ⇒ Object
- .position ⇒ Object
- .position=(value) ⇒ Object
-
.up_vector ⇒ Object
The “up” direction.
- .up_vector=(value) ⇒ Object
Class Method Details
.direction ⇒ Object
The forward direction of the listener (unit-length, doesn’t have to be). Default: (0, 0, -1) — looking into the screen.
35 36 37 |
# File 'lib/sfml/audio/listener.rb', line 35 def direction Vector3.from_native(C::Audio.sfListener_getDirection) end |
.direction=(value) ⇒ Object
39 40 41 42 |
# File 'lib/sfml/audio/listener.rb', line 39 def direction=(value) vec = value.is_a?(Vector3) ? value : Vector3.new(*value) C::Audio.sfListener_setDirection(vec.to_native_f) end |
.global_volume ⇒ Object
Master volume in the range [0, 100]. Affects all sounds, music, etc.
16 17 18 |
# File 'lib/sfml/audio/listener.rb', line 16 def global_volume C::Audio.sfListener_getGlobalVolume end |
.global_volume=(value) ⇒ Object
20 21 22 |
# File 'lib/sfml/audio/listener.rb', line 20 def global_volume=(value) C::Audio.sfListener_setGlobalVolume(value.to_f) end |
.position ⇒ Object
24 25 26 |
# File 'lib/sfml/audio/listener.rb', line 24 def position Vector3.from_native(C::Audio.sfListener_getPosition) end |
.position=(value) ⇒ Object
28 29 30 31 |
# File 'lib/sfml/audio/listener.rb', line 28 def position=(value) vec = value.is_a?(Vector3) ? value : Vector3.new(*value) C::Audio.sfListener_setPosition(vec.to_native_f) end |
.up_vector ⇒ Object
The “up” direction. Default: (0, 1, 0). Together with ‘direction` it determines listener orientation for stereo panning.
46 47 48 |
# File 'lib/sfml/audio/listener.rb', line 46 def up_vector Vector3.from_native(C::Audio.sfListener_getUpVector) end |