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

ParameterTypeDescription
filenamestrName 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:

PropertyTypeR/WDescription
loopboolR/WEnable looping
volumefloatR/WGain (clamped >= 0.0)
panfloatR/WStereo panning (-1.0 to 1.0)
timefloatRCurrent playback position (seconds)
durationfloatRTotal length (seconds)
finishedboolRTrue 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.