pyxen.Sound
A short audio clip attached to an Entity as a component.
Sounds are loaded entirely into memory — use them for short effects like jumps, hits, and pickups.
For audio concepts, see Audio.
Constructor
Sound(filename)
One required positional argument: the name of a WAV audio asset in the project.
Parameters
| Parameter | Type | Description |
|---|---|---|
filename | str | Name of the WAV asset |
Example
jump_sound = Sound("jump")
Attaching a Sound
During spawn:
sfx = world.spawn(sound=Sound("jump"))
Or later:
entity.sound = Sound("jump")
Assigning a sound starts playback immediately.
Component Properties
Access via entity.sound:
| Property | Type | R/W | Description |
|---|---|---|---|
loop | bool | R/W | Enable looping |
volume | float | R/W | Gain (clamped >= 0.0) |
pan | float | R/W | Stereo panning (-1.0 to 1.0) |
time | float | R | Current playback position (seconds) |
duration | float | R | Total length (seconds) |
finished | bool | R | True when playback has completed |
loop
entity.sound.loop = True
When enabled, the sound restarts automatically after finishing.
volume
entity.sound.volume = 0.5
Values below 0.0 are clamped to 0.0.
pan
entity.sound.pan = -1.0 # full left
entity.sound.pan = 1.0 # full right
entity.sound.pan = 0.0 # center
Clamped to the range -1.0 to 1.0.
time
t = entity.sound.time
Read-only. Current playback position in seconds.
duration
d = entity.sound.duration
Read-only. Total length of the sound in seconds.
finished
if entity.sound.finished:
world.destroy(entity)
Read-only. True when the sound has finished playing (and loop is False).
Format
Sound assets must be WAV files.
Common Errors
Missing Filename
Sound()
ValueError: Sound must have a file
Invalid Asset
Sound("nonexistent")
The sound object is created but playback will fail silently with a warning logged.