Skip to content

feat: Sound Component for Game ObjectsΒ #1030

@SelfDevTV

Description

@SelfDevTV

Is your feature request related to a problem? Please describe.

Currently, audio in Kaplay is handled globally via play(), which feels inconsistent with the engine's "everything is a component" philosophy. When I want sound tied to a game object's lifecycle (e.g., a looping hum on an enemy that should stop when the enemy is destroyed), I have to manually manage this with custom components and cleanup logic. It's not difficult, but it's boilerplate that the engine could handle natively β€” especially for spatial audio based on object position.

Any more information?

Summary

It would be great to have a built-in sound component that can be attached to game objects, similar to how sprite(), pos(), or other components work.

Motivation

Currently, audio is handled globally via play(), which feels inconsistent with Kaplay's "everything is a component" philosophy. Attaching sound to objects would enable:

  • Automatic cleanup when objects are destroyed (no orphaned audio)
  • Spatial/positional audio based on object position
  • Easier management of looping sounds tied to object lifecycle
  • More intuitive API that matches the rest of the engine

Proposed API

add([
    sprite("enemy"),
    pos(100, 100),
    sound("enemy_hum", { loop: true, spatial: true }),
])

Or perhaps split into sound() and spatialSound() for clarity.

Current Workaround

Custom components can achieve this, but it feels like core functionality that would benefit many users.

References

Other engines handle this well β€” e.g., Godot's AudioStreamPlayer2D as a node that can be part of a scene tree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions