UNPKG

hytopia

Version:

The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.

633 lines (279 loc) 7.05 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [server](./server.md) &gt; [Audio](./server.audio.md) ## Audio class Represents a audio playback in a world. **Signature:** ```typescript export default class Audio extends EventRouter implements protocol.Serializable ``` **Extends:** [EventRouter](./server.eventrouter.md) **Implements:** protocol.Serializable ## Remarks Audio instances are created directly as instances. They support a variety of configuration options through the [AudioOptions](./server.audiooptions.md) constructor argument. <h2>Events</h2> This class is an EventRouter, and instances of it emit events with payloads listed under [AudioEventPayloads](./server.audioeventpayloads.md) ## Example ```typescript (new Audio({ uri: 'music/song.mp3', // relative to the server's assets directory in the project root, resolves to assets/music/song.mp3 loop: true, volume: 0.5, })).play(world); ``` ## Constructors <table><thead><tr><th> Constructor </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [(constructor)(options)](./server.audio._constructor_.md) </td><td> </td><td> Constructs a new instance of the `Audio` class </td></tr> </tbody></table> ## Properties <table><thead><tr><th> Property </th><th> Modifiers </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td> [attachedToEntity](./server.audio.attachedtoentity.md) </td><td> `readonly` </td><td> [Entity](./server.entity.md) \| undefined </td><td> The entity to which the audio is attached if explicitly set. </td></tr> <tr><td> [cutoffDistance](./server.audio.cutoffdistance.md) </td><td> `readonly` </td><td> number </td><td> The cutoff distance where the audio will be reduced to 0 volume. </td></tr> <tr><td> [detune](./server.audio.detune.md) </td><td> `readonly` </td><td> number \| undefined </td><td> The detune of the audio in cents if explicitly set. </td></tr> <tr><td> [distortion](./server.audio.distortion.md) </td><td> `readonly` </td><td> number \| undefined </td><td> The amount of distortion to apply to the audio if explicitly set. </td></tr> <tr><td> [duration](./server.audio.duration.md) </td><td> `readonly` </td><td> number \| undefined </td><td> The duration of the audio in seconds if explicitly set. </td></tr> <tr><td> [id](./server.audio.id.md) </td><td> `readonly` </td><td> number \| undefined </td><td> The unique identifier for the audio. </td></tr> <tr><td> [isLoaded](./server.audio.isloaded.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the audio has loaded into the world. Audio is loaded the first time play() is called. </td></tr> <tr><td> [isPlaying](./server.audio.isplaying.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the audio is currently playing. </td></tr> <tr><td> [isPositional](./server.audio.ispositional.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the audio is positional (Entity or position attached). </td></tr> <tr><td> [loop](./server.audio.loop.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the audio is looped. </td></tr> <tr><td> [offset](./server.audio.offset.md) </td><td> `readonly` </td><td> number \| undefined </td><td> The offset time in seconds from which the audio should start playing if explicitly set. </td></tr> <tr><td> [playbackRate](./server.audio.playbackrate.md) </td><td> `readonly` </td><td> number \| undefined </td><td> The playback rate of the audio if explicitly set. </td></tr> <tr><td> [position](./server.audio.position.md) </td><td> `readonly` </td><td> [Vector3Like](./server.vector3like.md) \| undefined </td><td> The position of the audio in the world if explicitly set. </td></tr> <tr><td> [referenceDistance](./server.audio.referencedistance.md) </td><td> `readonly` </td><td> number </td><td> The reference distance of the audio if explicitly set. </td></tr> <tr><td> [startTick](./server.audio.starttick.md) </td><td> `readonly` </td><td> number \| undefined </td><td> The server tick at which the audio started playing. </td></tr> <tr><td> [uri](./server.audio.uri.md) </td><td> `readonly` </td><td> string </td><td> The URI of the audio asset. </td></tr> <tr><td> [volume](./server.audio.volume.md) </td><td> `readonly` </td><td> number \| undefined </td><td> The volume of the audio if explicitly set. </td></tr> <tr><td> [world](./server.audio.world.md) </td><td> `readonly` </td><td> [World](./server.world.md) \| undefined </td><td> The world the audio is in if already loaded. </td></tr> </tbody></table> ## Methods <table><thead><tr><th> Method </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [pause()](./server.audio.pause.md) </td><td> </td><td> Pauses the audio. </td></tr> <tr><td> [play(world, restart)](./server.audio.play.md) </td><td> </td><td> Plays or resumes the audio. </td></tr> <tr><td> [setAttachedToEntity(entity)](./server.audio.setattachedtoentity.md) </td><td> </td><td> Sets the entity to which the audio is attached, following its position. </td></tr> <tr><td> [setCutoffDistance(cutoffDistance)](./server.audio.setcutoffdistance.md) </td><td> </td><td> Sets the cutoff distance of the audio. </td></tr> <tr><td> [setDetune(detune)](./server.audio.setdetune.md) </td><td> </td><td> Sets the detune of the audio. </td></tr> <tr><td> [setDistortion(distortion)](./server.audio.setdistortion.md) </td><td> </td><td> Sets the distortion of the audio. </td></tr> <tr><td> [setPlaybackRate(playbackRate)](./server.audio.setplaybackrate.md) </td><td> </td><td> Sets the playback rate of the audio. </td></tr> <tr><td> [setPosition(position)](./server.audio.setposition.md) </td><td> </td><td> Sets the position of the audio. Will detach from entity if attached. </td></tr> <tr><td> [setReferenceDistance(referenceDistance)](./server.audio.setreferencedistance.md) </td><td> </td><td> Sets the reference distance of the audio. </td></tr> <tr><td> [setVolume(volume)](./server.audio.setvolume.md) </td><td> </td><td> Sets the volume of the audio. </td></tr> </tbody></table>