module SFML::Listener
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.
Public Instance Methods
Source
# File lib/sfml/audio/listener.rb, line 77 def cone SoundCone.from_native(C::Audio.sfListener_getCone) end
Directional cone for the listener — same shape as the cone on individual sound sources (see SFML::SoundCone). Used for cone-shaped attenuation when the listener faces a particular direction (think headphones turning to follow a character’s head).
Source
# File lib/sfml/audio/listener.rb, line 82 def cone=(value) cone = case value when SoundCone then value when Hash then SoundCone.new(**value) else raise ArgumentError, "Listener.cone= expects SoundCone or Hash; got #{value.class}" end C::Audio.sfListener_setCone(cone.to_native) end
Set the cone. Accepts a SoundCone or a Hash.
Source
# File lib/sfml/audio/listener.rb, line 38 def direction Vector3.from_native(C::Audio.sfListener_getDirection) end
The forward direction of the listener (unit-length, doesn’t have to be). Default: (0, 0, -1) — looking into the screen.
Source
# File lib/sfml/audio/listener.rb, line 43 def direction=(value) vec = value.is_a?(Vector3) ? value : Vector3.new(*value) C::Audio.sfListener_setDirection(vec.to_native_f) end
Set the forward direction — accepts Vector3 or [x, y, z].
Source
# File lib/sfml/audio/listener.rb, line 16 def global_volume C::Audio.sfListener_getGlobalVolume end
Master volume in the range [0, 100]. Affects all sounds, music, etc.
Source
# File lib/sfml/audio/listener.rb, line 21 def global_volume=(value) C::Audio.sfListener_setGlobalVolume(value.to_f) end
Set the master volume in [0, 100].
Source
# File lib/sfml/audio/listener.rb, line 26 def position Vector3.from_native(C::Audio.sfListener_getPosition) end
The listener’s 3D position in world space.
Source
# File lib/sfml/audio/listener.rb, line 31 def position=(value) vec = value.is_a?(Vector3) ? value : Vector3.new(*value) C::Audio.sfListener_setPosition(vec.to_native_f) end
Set the position — accepts Vector3 or [x, y, z].
Source
# File lib/sfml/audio/listener.rb, line 50 def up_vector Vector3.from_native(C::Audio.sfListener_getUpVector) end
The “up” direction. Default: (0, 1, 0). Together with direction it determines listener orientation for stereo panning.
Source
# File lib/sfml/audio/listener.rb, line 55 def up_vector=(value) vec = value.is_a?(Vector3) ? value : Vector3.new(*value) C::Audio.sfListener_setUpVector(vec.to_native_f) end
Set the up vector — accepts Vector3 or [x, y, z].
Source
# File lib/sfml/audio/listener.rb, line 62 def velocity Vector3.from_native(C::Audio.sfListener_getVelocity) end
Listener velocity in world units / second — used by the Doppler effect on sources whose doppler_factor is non-zero.
Source
# File lib/sfml/audio/listener.rb, line 67 def velocity=(value) vec = value.is_a?(Vector3) ? value : Vector3.new(*value) C::Audio.sfListener_setVelocity(vec.to_native_f) end
Set the velocity — accepts Vector3 or [x, y, z].