音频播放
cc.Class({ properties: { audioSource: { type: cc.AudioSource, default: null }, }, play: function () { this.audioSource.play(); }, pause: function () { this.audioSource.pause(); },});
使用 AudioEngine 播放
- 2.
所以我们不建议在 play 接口内直接填写音频的 url 地址,而是希望大家先定义一个 AudioClip,然后在编辑器内将音频拖拽过来。cc.Class({ properties: { audio: { url: cc.AudioClip, default: null } }, onLoad: function () { this.current = cc.audioEngine.play(this.audio, false, 1); }, onDestroy: function () { cc.audioEngine.stop(this.current); }});
