Audio

Pyxen supports two kinds of audio: sounds for short effects and music for longer tracks. Both are attached to entities as components.

Sounds

A Sound is a short audio clip — a jump, a hit, a coin pickup. You play a sound by spawning an entity with a Sound component:

world.spawn(sound=Sound("jump"))

The sound plays immediately. You can control playback properties:

world.spawn(sound=Sound("laser", loop=True, gain=0.5, pan=-0.5))
PropertyMeaning
loopWhether the sound repeats
gainVolume (0.0 = silent, 1.0 = full)
panStereo position (-1.0 = left, 0.0 = center, 1.0 = right)

Sounds are loaded from audio files in your project assets.

Music

Music works like Sound but is designed for longer tracks. Music is streamed rather than loaded entirely into memory:

world.spawn(music=Music("theme", loop=True))

Music supports the same properties: loop, gain, and pan.

Audio as components

Because audio is attached to entities, you manage it the same way as everything else:

# start background music
bgm = world.spawn(name="bgm", music=Music("overworld", loop=True))

# stop it later
world.destroy(bgm)

This fits naturally with the ECS model — audio is just another component on an entity, visible in the frame inspector like everything else.

Supported formats

Add audio files to your project through the asset manager in Pyxen.

For the full API, see Sound and Music.