Class: Audio

Audio(options)

Audio is the base class for game audio, loaded into a HTML5 'audio' tag.

Constructor

new Audio(options)

Create a new Audio with the specified options.
Parameters:
Name Type Description
options object The options object for the Asset - see below
Source:
Example
const { Asset } = require('tenkai')

var asset = new Asset({
  src: 'music/maintitle.mp3',   // Source file
  type: 'audio/mpeg',           // MIME type of the asset file
  startTime: 0,                 // Start offset in ms (optional)
  endTime: 1040,                // End offset in ms (optional)
  loop: true                    // Loop the audio continuously (optional, default false)
})

Methods

fadeIn(duration, callback)

Fade in the audio over the given duration then call the optional callback
Parameters:
Name Type Default Description
duration integer 1000 Fade duration in ms
callback function The callback function to invoke when the fade has completed
Source:

fadeOut(duration, callback)

Fade out the audio over the given duration then call the optional callback
Parameters:
Name Type Default Description
duration integer 1000 Fade duration in ms
callback function The callback function to invoke when the fade has completed
Source:

load(callback)

Load the Audio asynchronously from its src and optionally trigger the supplied callback when available.
Parameters:
Name Type Description
callback function The callback function to invoke when the asset has been loaded
Source:
Example
audio.load((err, au) => {
  console.log("Audio "+au.name+" Loaded")
})

pause()

Pause the audio at the current position.
Source:

play()

Play the audio from the current position.
Source:

playRange(start, end, start)

Play the audio from the start time index to the end time index and optionally loop.
Parameters:
Name Type Default Description
start float null The start offset in ms (optional)
end float null The end offset in ms (optional)
start boolean Loop the audio (optional)
Source:

stop()

Stop the audio and reset it to the beginning
Source: