Attenuation2D Module
2D positional attenuation: turns a listener facing plus listener/source positions into a Voice (Volume and Pan set, Pitch 1). This is the portable alternative to the MonoGame-only 3D audio surface — raylib has no listener model, so the Core contract only promises flat 2D attenuation.
Volume falls off linearly from 1.0 at the listener's position to 0.0 at maxDistance; sources beyond that distance are silent. Pan is the signed direction from the listener to the source along the listener's right-hand perpendicular, in the same coordinate system as the positions: with the usual screen coordinates (X right, Y down), a source below the listener plays on the right when the listener faces +X.
Example
let voice =
Attenuation2D.compute(facingRad, player.X, player.Y) (enemy.X, enemy.Y) 640.0f
audio.Play("enemy-step", voice)
Functions and values
| Function or value |
Description
|
Full Usage:
compute (arg1, arg1, arg1) (arg2, arg2) maxDistance
Parameters:
float32
arg1 : float32
arg2 : float32
arg3 : float32
arg4 : float32
maxDistance : float32
-
Distance in the same units at which the source falls silent.
Returns: Voice
A voice with linear distance volume and directional pan (Pitch 1).
|
Computes the Voice for a sound source heard by a 2D listener.
|
Mibo