handles both short sounds and music (GUI Only) More...
Public Member Functions | |
changeOffsetX (int targetOffset, int msDuration, int easing=linearTween) | |
change the left/right positioning of the sound's origin over time More... | |
changePitch (number targetOffset, int msDuration, int easing=easeInOutQuad) | |
change the pitch of a sound over time (NOT IMPLEMENTED) More... | |
changeVolume (number level, uint fadeMs, int easing=linearTween) | |
change sounds volume to target level over time More... | |
fadeIn (uint fadeMs, int easing=linearTween) | |
fade the sound in from zero to full volume over time More... | |
fadeOut (uint fadeMs, int easing=linearTween) | |
fade the sound out to silence over time More... | |
number | getVolume () |
get the current volume level for this sound More... | |
boolean | isLooping () |
find out if this sound is set to loop More... | |
boolean | isPaused () |
find out if a sound is paused More... | |
IEventHandler | on (int eventCode, function func) |
set a handler for a particular sound event More... | |
IEventHandler | onDonePlaying (function func) |
set a handler for when the sound finishes playing More... | |
IEventHandler | onFailedToPlay (function func) |
set a handler for if the sound fails to play More... | |
IEventHandler | onLooping (function func) |
set a handler for when the sound reaches the end and loops More... | |
pause () | |
stop a sound playing until resumed More... | |
play (number vol=1.0, int offsetX=0, number pitch=0, uint fromMs=0, int lenMs=ENTIRE_LENGTH) | |
play a sound once with given settings More... | |
resume () | |
unpause a sound that was paused More... | |
Sound | setLooping (boolean loopingOn) |
set if the sound should loop or not More... | |
Sound | setOffsetX (int offsetX) |
set the left/right positioning of the sound's origin More... | |
Sound | setPitch (number pitchOffset) |
set the pitch of a sound More... | |
Sound | setVolume (number inVolume) |
set the volume level for a sound More... | |
Sound | skip (int skipMilliseconds) |
skip ahead or back in a sound More... | |
Sound | skipTo (uint timeMs) |
skipTo a particular time position in a sound More... | |
start () | |
start playing a sound More... | |
stop () | |
stop a sound from playing More... | |
Public Member Functions inherited from EventEmitter | |
addHandler (IEventHandler inHandler, int inEventType=all_events) | |
add a new handler for some event type, or for all events if no type specified. More... | |
blockEvent (int inEventType) | |
temporarily ignore all events of a particular type. More... | |
clear () | |
remove all handlers More... | |
removeHandler (IEventHandler inHandler, int inEventType=all_events) | |
remove a handler for some event type, or for all events (see note) if no type specified. More... | |
unblockEvent (int inEventType) | |
stop ignoring events of a particular type More... | |
handles both short sounds and music (GUI Only)
This mode is typically used for short sound effects, like a footstep, an explosion, a single note of music, or some other momentary sound that doesn't need to be altered while playing. Use play() for that sort of fire and forget sound.
Fire and Forget Example:**
For longer sound effects and music, you will often want more dynamic control over the sound as it plays. The hum of a motor might change pitch and location as the sprite that generates it moves around on the screen. Background music may need to be paused or have it's volume changed independent of other sounds as it plays. Use start() to play those sorts of sounds, then call other methods as needed to alter the sound playback.
Dynamic Playback Example:**
changeOffsetX | ( | int | targetOffset, |
int | msDuration, | ||
int | easing = linearTween |
||
) |
change the left/right positioning of the sound's origin over time
Adjust the apparent left/right positioning of the sound over a period of time to make the sound appear to be coming from a particular location in the view port.
targetOffset | the target X offset from the center of the main view port |
msDuration | the amount of time to get there |
easing | the function for calculating the movement rate. Defaults to linearTween (smooth movement with no acceleration or deceleration). |
changePitch | ( | number | targetOffset, |
int | msDuration, | ||
int | easing = easeInOutQuad |
||
) |
change the pitch of a sound over time (NOT IMPLEMENTED)
changeVolume | ( | number | level, |
uint | fadeMs, | ||
int | easing = linearTween |
||
) |
change sounds volume to target level over time
The change can go in either direction, louder or quieter.
level | the target level |
fadeMs | the time to take for sound to reach the new volume level |
easing | the function that describes how the volume change should happen, defaults to linearTween (constant rate of change) |
fadeIn | ( | uint | fadeMs, |
int | easing = linearTween |
||
) |
fade the sound in from zero to full volume over time
fadeMs | the time to take for sound to reach full volume |
easing | the function that describes how the fading should happen, defaults to linearTween (constant rate of change) |
fadeOut | ( | uint | fadeMs, |
int | easing = linearTween |
||
) |
fade the sound out to silence over time
The sound is stopped once it fades out completely.
fadeMs | the time to take for sound to fade out completely |
easing | the function that describes how the fading should happen, defaults to linearTween (constant rate of change) |
getVolume | ( | ) |
get the current volume level for this sound
isLooping | ( | ) |
find out if this sound is set to loop
isPaused | ( | ) |
find out if a sound is paused
on | ( | int | eventCode, |
function | func | ||
) |
set a handler for a particular sound event
onDonePlaying | ( | function | func | ) |
set a handler for when the sound finishes playing
onFailedToPlay | ( | function | func | ) |
set a handler for if the sound fails to play
onLooping | ( | function | func | ) |
set a handler for when the sound reaches the end and loops
pause | ( | ) |
stop a sound playing until resumed
play | ( | number | vol = 1.0 , |
int | offsetX = 0 , |
||
number | pitch = 0 , |
||
uint | fromMs = 0 , |
||
int | lenMs = ENTIRE_LENGTH |
||
) |
play a sound once with given settings
Can be called multiple times on same sound object, creating overlapping sounds. Internally, play() creates a new sound instance that is automatically cleaned up when the sound has finished playing.
vol | the volume level from 0.0 to 1.0, defaults to 1.0 |
offsetX | the left/right position offset from the center of the screen for the sound source. The pan/balance for the sound is adjusted accordingly. Negative numbers are from the left, positive to the right. Defaults to zero (no balance adjustment). |
pitch | the amount to shift the pitch -1.0 is down one octave, +1.0 is up one octave. |
fromMs | start the sound from a particular ms time mark |
lenMs | the maximum number of ms to play the sound. If longer than the length of the sound this parameter is ignored. Defaults to playing the entire length of the sound. |
resume | ( | ) |
unpause a sound that was paused
Play continues from where it was before it was paused.
setLooping | ( | boolean | loopingOn | ) |
set if the sound should loop or not
setOffsetX | ( | int | offsetX | ) |
set the left/right positioning of the sound's origin
Set the apparent left/right positioning of the sound to make the sound appear to be coming from a particular location in the view port.
offsetX | the target X offset from the center of the main view port |
setPitch | ( | number | pitchOffset | ) |
set the pitch of a sound
Raise or lower the pitch of a sound by up to an octave.
pitchOffset | a value between -1.0 and 1.0, with -1.0 meaning down an octave, and +1.0 being up an octave. |
setVolume | ( | number | inVolume | ) |
set the volume level for a sound
Sets the volume level for this specific sound.
inVolume | a value between 0.0 and 1.0, where 0 is silent and 1.0 is the max volume allowed by the master volume. |
skip | ( | int | skipMilliseconds | ) |
skip ahead or back in a sound
skipMilliseconds | the amount of time to skip. Negative values are backwards. |
skipTo | ( | uint | timeMs | ) |
skipTo a particular time position in a sound
timeMs | the location within the sound to skip to |
start | ( | ) |