Fork me on GitHub
View source

package haxepunk

class Sfx

Sound effect object used to play embedded sounds.

Static functions

View source

static getPan (type : String) : Float

Return a sound type's pan setting. This factors in global panning. See HXP.pan.


Parameters:
type   

The type to get the pan from.


Returns:

The pan for the type.

View source

static getVolume (type : String) : Float

Return a sound type's volume setting. This factors in global volume. See HXP.volume.


Parameters:
type   

The type to get the volume from.


Returns:

The volume for the type.

View source

static onGlobalUpdated (updatePan : Bool) : Void

Called by HXP when global volume or panning are changed on native targets. Updates all sounds to the correct volume or pan, depending on the updatePan setting.


Parameters:
updatePan   

True indicates pan changed, false indicates volume changed.

View source

static setPan (type : String, pan : Float) : Void

Set a sound type's pan. Sfx instances of this type will add this pan to their own.


Parameters:
type   

The type to set.

pan   

The pan value.

View source

static setVolume (type : String, volume : Float) : Void

Set a sound type's volume. Sfx instances of this type will multiply their volume by this value.


Parameters:
type   

The type to set.

volume   

The volume value.

Constructor

View source

new (source : Dynamic, complete : Void ->Void, ) : Void

Creates a sound effect from an embedded source. Store a reference to this object so that you can play the sound using play() or loop().


Parameters:
source   

The embedded sound class to use.

complete   

Optional callback function for when the sound finishes playing.

Variables

read only length : Float

Length of the sound, in seconds.

pan : Float

Alter the panning factor (a value from -1 to 1) of the sound during playback. Panning only applies to mono sounds. It is ignored on stereo.

read only playing : Bool

If the sound is currently playing.

read only position : Float

Position of the currently playing sound, in seconds.

type : String

Change the sound type. This an arbitrary string you can use to group sounds to mute or pan en masse.

volume : Float

Alter the volume factor (a value from 0 to 1) of the sound during playback.

Functions

View source

loop (vol : Float = 1, pan : Float = 0) : Void

Plays the sound looping. Will loop continuously until you call stop(), play(), or loop() again.


Parameters:
vol   

Volume factor, a value from 0 to 1.

pan   

Panning factor, a value from -1 to 1.

View source

play (volume : Float = 1, pan : Float = 0, loop : Bool = false) : Void

Plays the sound once.


Parameters:
vol   

Volume factor, a value from 0 to 1.

pan   

Panning factor, a value from -1 to 1.

loop   

If the audio should loop infinitely

View source

resume () : Void

Resumes the sound from the position stop() was called on it.

View source

stop () : Bool

Stops the sound if it is currently playing.


Returns:

If the sound was stopped.