Difference between revisions of "love.audio.newSource"

m
m (Noted in description that you can also use SoundData and Decoder.)
Line 1: Line 1:
Creates a new Source from a file.
+
Creates a new [[Source]] from a file, [[SoundData]], or [[Decoder]].
 
Sources created from SoundData are always static.
 
Sources created from SoundData are always static.
 
{{newobjectnotice}}
 
{{newobjectnotice}}
Line 57: Line 57:
 
* [[Constructs::Source]]
 
* [[Constructs::Source]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Creates a new Source from a file.
+
{{#set:Description=Creates a new [[Source]] from a file, [[SoundData]], or [[Decoder]].
 
}}
 
}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.audio.newSource}}
 
{{i18n|love.audio.newSource}}

Revision as of 15:55, 30 January 2012

Creates a new Source from a file, SoundData, or Decoder. Sources created from SoundData are always static.

O.png This function can be slow if it is called repeatedly, such as from love.update or love.draw. If you need to use a specific resource often, create it once and store it somewhere it can be reused!  



Function

Synopsis

source = love.audio.newSource( file, type )

Arguments

string file
The file to create a Source from.
SourceType type
Streaming or static source.

Returns

Source source
A new Source that can play the specified audio.

Function

Synopsis

source = love.audio.newSource( data )

Arguments

SoundData data
The SoundData to create a Source from.

Returns

Source source
A new Source that can play the specified audio. The SourceType of the returned audio is "static".

Function

Synopsis

source = love.audio.newSource( decoder, type )

Arguments

Decoder decoder
The Decoder to create a Source from.
SourceType type
Streaming or static source.

Returns

Source source
A new Source that can play the specified audio.

Examples

Load background music and play it

bgm = love.audio.newSource("bgm.ogg", "stream")
love.audio.play(bgm)

Load a sound effect and play it

sfx = love.audio.newSource("sfx.wav", "static")
love.audio.play(sfx)

Load SoundData and create a Source

data = love.sound.newSoundData("sfx.wav")
sfx = love.audio.newSource(data)

Load Decoder and create a Source

decoder = love.sound.newDecoder("bgm.ogg")
bgm = love.audio.newSource(decoder)

See Also


Other Languages