Cocos Creator API

1.3.0

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

audioEngine static

: cc

cc.audioEngine is the singleton object, it provide simple audio APIs.

play
(
  • filePath
  • loop
  • volume
)
Number

Play audio.

filePath String

The path of the audio file without filename extension.

loop Boolean

Whether the music loop or not.

volume Number

Volume size.

:

: Number

audioId

:

//example
var audioID = cc.audioEngine.play(path, false, 0.5);

setLoop
(
  • audioID
  • loop
)

Set audio loop.

audioID Number

audio id.

loop Boolean

Whether cycle.

:

//example
cc.audioEngine.setLoop(id, true);

isLoop
(
  • audioID
)
Boolean

Get audio cycle state.

audioID Number

audio id.

:

: Boolean

Whether cycle.

:

//example
cc.audioEngine.isLoop(id);

setVolume
(
  • audioID
  • volume
)

Set the volume of audio.

audioID Number

audio id.

volume Number

Volume must be in 0.0~1.0 .

:

//example
cc.audioEngine.setVolume(0.5);

getVolume
(
  • audioID
)
Boolean

The volume of the music max value is 1.0,the min value is 0.0 .

audioID Number

audio id.

:

:

//example
var volume = cc.audioEngine.getVolume(id);

setCurrentTime
(
  • audioID
  • sec
)
Boolean

Set current time

audioID Number

audio id.

sec Number

current time.

:

:

//example
cc.audioEngine.setCurrentTime(id, 2);

getCurrentTime
(
  • audioID
)
Number

Get current time

audioID Number

audio id.

:

: Number

audio current time.

:

//example
var time = cc.audioEngine.getCurrentTime(id);

getDuration
(
  • audioID
)
Number

Get audio duration

audioID Number

audio id.

:

: Number

audio duration.

:

//example
var time = cc.audioEngine.getDuration(id);

getState
(
  • audioID
)
cc.audioEngine.AudioState

Get audio state

audioID Number

audio id.

:

: cc.audioEngine.AudioState

audio duration.

:

//example
var state = cc.audioEngine.getState(id);

getState
(
  • audioID
  • callback
)

Get audio state

audioID Number

audio id.

callback Function

loaded callback.

:

//example
cc.audioEngine.setFinishCallback(id, function () {});

pause
(
  • audioID
)

Pause playing audio.

audioID Number

The return value of function play.

:

//example
cc.audioEngine.pause(audioID);

pauseAll ( )

Pause all playing audio

:

//example
cc.audioEngine.pauseAll();

resume
(
  • audioID
)

Resume playing audio.

audioID Number

The return value of function play. //example cc.audioEngine.resume(audioID);

resumeAll ( )

Resume all playing audio.

:

//example
cc.audioEngine.resumeAll();

stop
(
  • audioID
)

Stop playing audio.

audioID Number

The return value of function play.

:

//example
cc.audioEngine.stop(audioID);

stopAll ( )

Stop all playing audio.

:

//example
cc.audioEngine.stopAll();

setMaxAudioInstance
(
  • num
)

Set up an audio can generate a few examples.

num Number

a number of instances to be created from within an audio

:

//example
cc.audioEngine.setMaxAudioInstance(20);

getMaxAudioInstance ( ) Number

Getting audio can produce several examples.

:

: Number

a number of instances to be created from within an audio

:

//example
cc.audioEngine.getMaxAudioInstance();

uncache
(
  • filePath
)

Unload the preloaded audio from internal buffer.

filePath String

:

//example
cc.audioEngine.uncache(filePath);

uncacheAll ( )

Unload all audio from internal buffer.

:

//example
cc.audioEngine.uncacheAll();

preload
(
  • filePath
  • callback
)

Preload audio file.

filePath Unknown

The file path of an audio.

callback Unknown

The callback of an audio.

:

//example
cc.audioEngine.preload(path);

setMaxWebAudioSize
(
  • kb
)

Set a size, the unit is KB,Over this size is directly resolved into DOM nodes

kb Unknown

The file path of an audio.

:

//example
cc.audioEngine.setMaxWebAudioSize(300);

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index