mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
+3
-2
@@ -377,8 +377,8 @@ if (CC_DEBUG) {
|
||||
" set %s (value) {\n" +
|
||||
" ...\n" +
|
||||
" }",
|
||||
"3656": "The default value of %s.%s must be an empty string. (changed since 1.8)",
|
||||
"3657": "The value assigned to %s should be Texture2D object, not url string. Since 1.8,\n" +
|
||||
"3656": "The default value of %s.%s must be an empty string. (changed since 1.10)",
|
||||
"3657": "The value assigned to %s should be Texture2D object, not url string. Since 1.10`,\n" +
|
||||
"you can declare a texture object directly in properties by using:\n" +
|
||||
"{\n" +
|
||||
" default: null,\n" +
|
||||
@@ -725,5 +725,6 @@ if (CC_DEBUG) {
|
||||
"8301": "Camera does not support Canvas Mode.", //cc.Camera.enabled
|
||||
// AudioEngine: 8400
|
||||
"8400": "Wrong type arguments, 'filePath' must be a String.", // cc.audioEngine.play
|
||||
"8401": "Since 1.10, `%s` accept cc.AudioClip instance directly, not a URL string. Please directly reference the AudioClip object in your script, or load cc.AudioClip by loader first. Don't use audio's URL anymore.",
|
||||
};
|
||||
}
|
||||
|
||||
+84
-85
@@ -27,6 +27,7 @@
|
||||
|
||||
var EventTarget = require('../core/event/event-target');
|
||||
var sys = require('../core/platform/CCSys');
|
||||
var LoadMode = require('../core/assets/CCAudioClip').LoadMode;
|
||||
|
||||
var touchBinded = false;
|
||||
var touchPlayList = [
|
||||
@@ -37,14 +38,14 @@ var Audio = function (src) {
|
||||
EventTarget.call(this);
|
||||
|
||||
this._src = src;
|
||||
this._audioType = Audio.Type.UNKNOWN;
|
||||
this._element = null;
|
||||
this.id = 0;
|
||||
|
||||
this._volume = 1;
|
||||
this._loop = false;
|
||||
this._nextTime = 0; // playback position to set
|
||||
|
||||
this._eventList = {};
|
||||
this._state = Audio.State.INITIALZING;
|
||||
this._loaded = false;
|
||||
|
||||
this._isLoading = false;
|
||||
|
||||
this._onended = function () {
|
||||
this.emit('ended');
|
||||
@@ -53,20 +54,13 @@ var Audio = function (src) {
|
||||
|
||||
cc.js.extend(Audio, EventTarget);
|
||||
|
||||
Audio.Type = {
|
||||
DOM: 'AUDIO',
|
||||
WEBAUDIO: 'WEBAUDIO',
|
||||
NATIVE: 'NATIVE',
|
||||
UNKNOWN: 'UNKNOWN'
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Audio state.
|
||||
* !#zh 声音播放状态
|
||||
* @enum audioEngine.AudioState
|
||||
* @memberof cc
|
||||
*/
|
||||
|
||||
// TODO - At present, the state is mixed with two states of users and systems, and it is best to split into two types. A "loading" should also be added to the system state.
|
||||
Audio.State = {
|
||||
/**
|
||||
* @property {Number} ERROR
|
||||
@@ -88,49 +82,9 @@ Audio.State = {
|
||||
|
||||
(function (proto) {
|
||||
|
||||
proto.preload = function () {
|
||||
var src = this._src, audio = this;
|
||||
|
||||
if (this._isLoading) {
|
||||
return;
|
||||
}
|
||||
this._isLoading = true;
|
||||
|
||||
if (!src) {
|
||||
this._src = '';
|
||||
this._audioType = Audio.Type.UNKNOWN;
|
||||
this._element = null;
|
||||
this._state = Audio.State.INITIALZING;
|
||||
this._loaded = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var item = cc.loader.getItem(src);
|
||||
|
||||
if (!item) {
|
||||
item = cc.loader.getItem(src + '?useDom=1');
|
||||
}
|
||||
|
||||
// If the resource does not exist
|
||||
if (!item || !item.complete) {
|
||||
return cc.loader.load(src, function (error) {
|
||||
if (!error && src === audio._src) {
|
||||
var item = cc.loader.getItem(src);
|
||||
audio.mount(item.element || item.buffer);
|
||||
audio.emit('load');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
audio.mount(item.element || item.buffer);
|
||||
audio.emit('load');
|
||||
}
|
||||
|
||||
// current and volume
|
||||
};
|
||||
|
||||
proto._bindEnded = function (callback) {
|
||||
callback = callback || this._onended;
|
||||
if (this._audioType === Audio.Type.DOM) {
|
||||
if (this._src && this._src.loadMode === LoadMode.DOM_AUDIO) {
|
||||
this._element.addEventListener('ended', callback);
|
||||
} else {
|
||||
this._element.onended = callback;
|
||||
@@ -138,35 +92,54 @@ Audio.State = {
|
||||
};
|
||||
|
||||
proto._unbindEnded = function () {
|
||||
if (this._audioType === Audio.Type.DOM) {
|
||||
if (this._src && this._src.loadMode === LoadMode.DOM_AUDIO) {
|
||||
this._element.removeEventListener('ended', this._onended);
|
||||
} else {
|
||||
this._element.onended = null;
|
||||
}
|
||||
};
|
||||
|
||||
proto.mount = function (elem) {
|
||||
if (sys.platform === sys.WECHAT_GAME || elem instanceof HTMLElement) {
|
||||
// proto.mount = function (elem) {
|
||||
// if (CC_DEBUG) {
|
||||
// cc.warn('Audio.mount(value) is deprecated. Please use Audio._onLoaded().');
|
||||
// }
|
||||
// };
|
||||
|
||||
proto._onLoaded = function () {
|
||||
if (this._src.loadMode === LoadMode.DOM_AUDIO) {
|
||||
this._element = document.createElement('audio');
|
||||
this._element.src = elem.src;
|
||||
this._audioType = Audio.Type.DOM;
|
||||
} else {
|
||||
this._element = new WebAudioElement(elem, this);
|
||||
this._audioType = Audio.Type.WEBAUDIO;
|
||||
this._element.src = this._src._nativeAsset.src;
|
||||
}
|
||||
else {
|
||||
this._element = new WebAudioElement(this._src._nativeAsset, this);
|
||||
}
|
||||
|
||||
this.setVolume(this._volume);
|
||||
this.setLoop(this._loop);
|
||||
if (this._nextTime !== 0) {
|
||||
this.setCurrentTime(this._nextTime);
|
||||
}
|
||||
if (this._state === Audio.State.PLAYING) {
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this._state = Audio.State.INITIALZING;
|
||||
}
|
||||
this._state = Audio.State.INITIALZING;
|
||||
this._loaded = true;
|
||||
};
|
||||
|
||||
proto.play = function () {
|
||||
if (!this._element) return;
|
||||
this._bindEnded();
|
||||
this._element.play();
|
||||
this.emit('play');
|
||||
// marked as playing so it will playOnLoad
|
||||
this._state = Audio.State.PLAYING;
|
||||
|
||||
if (sys.platform !== sys.WECHAT_GAME &&
|
||||
this._audioType === Audio.Type.DOM &&
|
||||
if (!this._element) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._bindEnded();
|
||||
this._element.play();
|
||||
|
||||
if (sys.platform !== sys.WECHAT_GAME &&
|
||||
this._src && this._src.loadMode === LoadMode.DOM_AUDIO &&
|
||||
this._element.paused) {
|
||||
touchPlayList.push({ instance: this, offset: 0, audio: this._element });
|
||||
}
|
||||
@@ -193,7 +166,6 @@ Audio.State = {
|
||||
if (!this._element) return;
|
||||
this._unbindEnded();
|
||||
this._element.pause();
|
||||
this.emit('pause');
|
||||
this._state = Audio.State.PAUSED;
|
||||
};
|
||||
|
||||
@@ -201,7 +173,6 @@ Audio.State = {
|
||||
if (!this._element || this._element.currentTime === 0) return;
|
||||
this._bindEnded();
|
||||
this._element.play();
|
||||
this.emit('resume');
|
||||
this._state = Audio.State.PLAYING;
|
||||
};
|
||||
|
||||
@@ -232,23 +203,34 @@ Audio.State = {
|
||||
};
|
||||
|
||||
proto.setLoop = function (loop) {
|
||||
if (!this._element) return;
|
||||
this._element.loop = loop;
|
||||
this._loop = loop;
|
||||
if (this._element) {
|
||||
this._element.loop = loop;
|
||||
}
|
||||
};
|
||||
proto.getLoop = function () {
|
||||
return this._element && this._element.loop;
|
||||
return this._loop;
|
||||
};
|
||||
|
||||
proto.setVolume = function (num) {
|
||||
if (!this._element) return;
|
||||
this._element.volume = num;
|
||||
this._volume = num;
|
||||
if (this._element) {
|
||||
this._element.volume = num;
|
||||
}
|
||||
};
|
||||
proto.getVolume = function () {
|
||||
return this._element ? this._element.volume : 1;
|
||||
return this._volume;
|
||||
};
|
||||
|
||||
proto.setCurrentTime = function (num) {
|
||||
if (!this._element) return;
|
||||
if (this._element) {
|
||||
this._nextTime = 0;
|
||||
}
|
||||
else {
|
||||
this._nextTime = num;
|
||||
return;
|
||||
}
|
||||
|
||||
this._unbindEnded();
|
||||
if (sys.platform !== sys.WECHAT_GAME) {
|
||||
this._bindEnded(function () {
|
||||
@@ -257,7 +239,8 @@ Audio.State = {
|
||||
}
|
||||
try {
|
||||
this._element.currentTime = num;
|
||||
} catch (err) {
|
||||
}
|
||||
catch (err) {
|
||||
var _element = this._element;
|
||||
if (_element.addEventListener) {
|
||||
var func = function () {
|
||||
@@ -278,7 +261,7 @@ Audio.State = {
|
||||
|
||||
proto.getState = function () {
|
||||
var elem = this._element;
|
||||
if (Audio.State.PLAYING === this._state && elem.paused) {
|
||||
if (elem && Audio.State.PLAYING === this._state && elem.paused) {
|
||||
this._state = Audio.State.PAUSED;
|
||||
}
|
||||
return this._state;
|
||||
@@ -287,11 +270,27 @@ Audio.State = {
|
||||
proto.__defineGetter__('src', function () {
|
||||
return this._src;
|
||||
});
|
||||
proto.__defineSetter__('src', function (string) {
|
||||
if (string !== this._src) {
|
||||
this._isLoading = false;
|
||||
proto.__defineSetter__('src', function (clip) {
|
||||
if (clip) {
|
||||
this._src = clip;
|
||||
if (clip.loaded) {
|
||||
this._onLoaded();
|
||||
}
|
||||
else {
|
||||
var self = this;
|
||||
clip.once('load', function () {
|
||||
if (clip === self._src) {
|
||||
self._onLoaded();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return this._src = string;
|
||||
else {
|
||||
this._src = null;
|
||||
this._element = null;
|
||||
this._state = Audio.State.INITIALZING;
|
||||
}
|
||||
return clip;
|
||||
});
|
||||
|
||||
proto.__defineGetter__('paused', function () {
|
||||
|
||||
+109
-90
@@ -26,6 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
var Audio = require('./CCAudio');
|
||||
var AudioClip = require('../core/assets/CCAudioClip');
|
||||
|
||||
var instanceId = 0;
|
||||
var id2audio = {};
|
||||
@@ -37,25 +38,23 @@ var getAudioFromPath = function (path) {
|
||||
if (!list) {
|
||||
list = url2id[path] = [];
|
||||
}
|
||||
var audio;
|
||||
if (audioEngine._maxAudioInstance <= list.length) {
|
||||
var oldId = list.shift();
|
||||
var oldAudio = id2audio[oldId];
|
||||
oldAudio.stop();
|
||||
}
|
||||
|
||||
audio = new Audio(path);
|
||||
var audio = new Audio();
|
||||
var callback = function () {
|
||||
var id = this.instanceId;
|
||||
delete id2audio[id];
|
||||
var index = list.indexOf(id);
|
||||
delete id2audio[this.id];
|
||||
var index = list.indexOf(this.id);
|
||||
cc.js.array.fastRemoveAt(list, index);
|
||||
};
|
||||
audio.on('ended', callback);
|
||||
audio.on('stop', callback);
|
||||
id2audio[id] = audio;
|
||||
|
||||
audio.instanceId = id;
|
||||
audio.id = id;
|
||||
list.push(id);
|
||||
|
||||
return audio;
|
||||
@@ -91,33 +90,47 @@ var audioEngine = {
|
||||
* !#en Play audio.
|
||||
* !#zh 播放音频
|
||||
* @method play
|
||||
* @param {String} filePath - The path of the audio file without filename extension.
|
||||
* @param {AudioClip} clip - The audio clip to play.
|
||||
* @param {Boolean} loop - Whether the music loop or not.
|
||||
* @param {Number} volume - Volume size.
|
||||
* @return {Number} audioId
|
||||
* @example
|
||||
* var audioID = cc.audioEngine.play(path, false, 0.5);
|
||||
* cc.loader.loadRes(url, cc.AudioClip, function (err, clip) {
|
||||
* var audioID = cc.audioEngine.play(clip, false, 0.5);
|
||||
* });
|
||||
*/
|
||||
play: function (filePath, loop, volume/*, profile*/) {
|
||||
if (CC_DEBUG && (typeof filePath !== 'string')) {
|
||||
cc.errorID(8400);
|
||||
return;
|
||||
play: function (clip, loop, volume/*, profile*/) {
|
||||
var path = clip;
|
||||
var audio;
|
||||
if (typeof clip === 'string') {
|
||||
// backward compatibility since 1.10
|
||||
cc.warnID(8401, 'cc.audioEngine');
|
||||
path = clip;
|
||||
// load clip
|
||||
audio = getAudioFromPath(path);
|
||||
AudioClip._loadByUrl(path, function (err, clip) {
|
||||
if (clip) {
|
||||
audio.src = clip;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (!clip) {
|
||||
return;
|
||||
}
|
||||
path = clip.nativeUrl;
|
||||
audio = getAudioFromPath(path);
|
||||
audio.src = clip;
|
||||
}
|
||||
|
||||
var audio = getAudioFromPath(filePath);
|
||||
var callback = function () {
|
||||
audio.setLoop(loop || false);
|
||||
if (typeof volume != 'number' || isNaN(volume)) {
|
||||
volume = 1;
|
||||
}
|
||||
audio.setVolume(volume);
|
||||
audio.play();
|
||||
};
|
||||
audio.__callback = callback;
|
||||
audio.on('load', callback);
|
||||
audio.preload();
|
||||
audio.setLoop(loop || false);
|
||||
if (typeof volume !== 'number') {
|
||||
volume = 1;
|
||||
}
|
||||
audio.setVolume(volume);
|
||||
audio.play();
|
||||
|
||||
return audio.instanceId;
|
||||
return audio.id;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -163,15 +176,9 @@ var audioEngine = {
|
||||
*/
|
||||
setVolume: function (audioID, volume) {
|
||||
var audio = getAudioFromId(audioID);
|
||||
if (!audio) return;
|
||||
if (!audio._loaded) {
|
||||
audio.once('load', function () {
|
||||
if (audio.setVolume)
|
||||
audio.setVolume(volume);
|
||||
});
|
||||
}
|
||||
if (audio.setVolume)
|
||||
if (audio) {
|
||||
audio.setVolume(volume);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -185,9 +192,7 @@ var audioEngine = {
|
||||
*/
|
||||
getVolume: function (audioID) {
|
||||
var audio = getAudioFromId(audioID);
|
||||
if (!audio || !audio.getVolume)
|
||||
return 1;
|
||||
return audio.getVolume();
|
||||
return audio ? audio.getVolume() : 1;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -202,17 +207,13 @@ var audioEngine = {
|
||||
*/
|
||||
setCurrentTime: function (audioID, sec) {
|
||||
var audio = getAudioFromId(audioID);
|
||||
if (!audio) return false;
|
||||
if (!audio._loaded) {
|
||||
audio.once('load', function () {
|
||||
if (audio.setCurrentTime)
|
||||
audio.setCurrentTime(sec);
|
||||
});
|
||||
if (audio) {
|
||||
audio.setCurrentTime(sec);
|
||||
return true;
|
||||
}
|
||||
if (audio.setCurrentTime)
|
||||
audio.setCurrentTime(sec);
|
||||
return true;
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -226,9 +227,7 @@ var audioEngine = {
|
||||
*/
|
||||
getCurrentTime: function (audioID) {
|
||||
var audio = getAudioFromId(audioID);
|
||||
if (!audio || !audio.getCurrentTime)
|
||||
return 0;
|
||||
return audio.getCurrentTime();
|
||||
return audio ? audio.getCurrentTime() : 0;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -242,9 +241,7 @@ var audioEngine = {
|
||||
*/
|
||||
getDuration: function (audioID) {
|
||||
var audio = getAudioFromId(audioID);
|
||||
if (!audio || !audio.getDuration)
|
||||
return 0;
|
||||
return audio.getDuration();
|
||||
return audio ? audio.getDuration() : 0;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -258,9 +255,7 @@ var audioEngine = {
|
||||
*/
|
||||
getState: function (audioID) {
|
||||
var audio = getAudioFromId(audioID);
|
||||
if (!audio || !audio.getState)
|
||||
return this.AudioState.ERROR;
|
||||
return audio.getState();
|
||||
return audio ? audio.getState() : this.AudioState.ERROR;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -292,10 +287,13 @@ var audioEngine = {
|
||||
*/
|
||||
pause: function (audioID) {
|
||||
var audio = getAudioFromId(audioID);
|
||||
if (!audio || !audio.pause)
|
||||
if (audio) {
|
||||
audio.pause();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
audio.pause();
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
_pauseIDCache: [],
|
||||
@@ -327,12 +325,13 @@ var audioEngine = {
|
||||
*/
|
||||
resume: function (audioID) {
|
||||
var audio = getAudioFromId(audioID);
|
||||
if (!audio || !audio.resume)
|
||||
return false;
|
||||
if (audio.getCurrentTime() === 0) {
|
||||
audio.play();
|
||||
} else {
|
||||
audio.resume();
|
||||
if (audio) {
|
||||
if (audio.getCurrentTime() === 0) {
|
||||
audio.play();
|
||||
}
|
||||
else {
|
||||
audio.resume();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -344,12 +343,13 @@ var audioEngine = {
|
||||
* cc.audioEngine.resumeAll();
|
||||
*/
|
||||
resumeAll: function () {
|
||||
while (this._pauseIDCache.length > 0) {
|
||||
var id = this._pauseIDCache.pop();
|
||||
for (var i = 0; i < this._pauseIDCache.length; ++i) {
|
||||
var id = this._pauseIDCache[i];
|
||||
var audio = getAudioFromId(id);
|
||||
if (audio && audio.resume)
|
||||
if (audio)
|
||||
audio.resume();
|
||||
}
|
||||
this._pauseIDCache.length = 0;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -362,11 +362,13 @@ var audioEngine = {
|
||||
*/
|
||||
stop: function (audioID) {
|
||||
var audio = getAudioFromId(audioID);
|
||||
if (!audio || !audio.stop)
|
||||
if (audio) {
|
||||
audio.stop();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
audio.off('load', audio.__callback);
|
||||
audio.stop();
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -379,9 +381,8 @@ var audioEngine = {
|
||||
stopAll: function () {
|
||||
for (var id in id2audio) {
|
||||
var audio = id2audio[id];
|
||||
if (audio && audio.stop) {
|
||||
if (audio) {
|
||||
audio.stop();
|
||||
audio.off('load', audio.__callback);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -414,11 +415,24 @@ var audioEngine = {
|
||||
* !#en Unload the preloaded audio from internal buffer.
|
||||
* !#zh 卸载预加载的音频。
|
||||
* @method uncache
|
||||
* @param {String} filePath
|
||||
* @param {AudioClip} clip
|
||||
* @example
|
||||
* cc.audioEngine.uncache(filePath);
|
||||
*/
|
||||
uncache: function (filePath) {
|
||||
uncache: function (clip) {
|
||||
var filePath = clip;
|
||||
if (typeof clip === 'string') {
|
||||
// backward compatibility since 1.10
|
||||
cc.warnID(8401, 'cc.audioEngine');
|
||||
filePath = clip;
|
||||
}
|
||||
else {
|
||||
if (!clip) {
|
||||
return;
|
||||
}
|
||||
filePath = clip.nativeUrl;
|
||||
}
|
||||
|
||||
var list = url2id[filePath];
|
||||
if (!list) return;
|
||||
while (list.length > 0) {
|
||||
@@ -467,8 +481,13 @@ var audioEngine = {
|
||||
* @param {Function} [callback] - The callback of an audio.
|
||||
* @example
|
||||
* cc.audioEngine.preload(path);
|
||||
* @deprecated `cc.audioEngine.preload` is deprecated, use `cc.loader.loadRes(url, cc.AudioClip)` instead please.
|
||||
*/
|
||||
preload: function (filePath, callback) {
|
||||
if (CC_DEBUG) {
|
||||
cc.warn('`cc.audioEngine.preload` is deprecated, use `cc.loader.loadRes(url, cc.AudioClip)` instead please.');
|
||||
}
|
||||
|
||||
cc.loader.load(filePath, callback && function (error) {
|
||||
if (!error) {
|
||||
callback();
|
||||
@@ -532,16 +551,18 @@ var audioEngine = {
|
||||
* !#en Play background music
|
||||
* !#zh 播放背景音乐
|
||||
* @method playMusic
|
||||
* @param {String} filePath - The path of the audio file without filename extension.
|
||||
* @param {AudioClip} clip - The audio clip to play.
|
||||
* @param {Boolean} loop - Whether the music loop or not.
|
||||
* @return {Number} audioId
|
||||
* @example
|
||||
* var audioID = cc.audioEngine.playMusic(path, false);
|
||||
* cc.loader.loadRes(url, cc.AudioClip, function (err, clip) {
|
||||
* var audioID = cc.audioEngine.playMusic(clip, false);
|
||||
* });
|
||||
*/
|
||||
playMusic: function (filePath, loop) {
|
||||
playMusic: function (clip, loop) {
|
||||
var music = this._music;
|
||||
this.stop(music.id);
|
||||
music.id = this.play(filePath, loop, music.volume);
|
||||
music.id = this.play(clip, loop, music.volume);
|
||||
music.loop = loop;
|
||||
return music.id;
|
||||
},
|
||||
@@ -624,15 +645,16 @@ var audioEngine = {
|
||||
* !#en Play effect audio.
|
||||
* !#zh 播放音效
|
||||
* @method playEffect
|
||||
* @param {String} filePath - The path of the audio file without filename extension.
|
||||
* @param {AudioClip} clip - The audio clip to play.
|
||||
* @param {Boolean} loop - Whether the music loop or not.
|
||||
* @return {Number} audioId
|
||||
* @example
|
||||
* var audioID = cc.audioEngine.playEffect(path, false);
|
||||
* cc.loader.loadRes(url, cc.AudioClip, function (err, clip) {
|
||||
* var audioID = cc.audioEngine.playEffect(clip, false);
|
||||
* });
|
||||
*/
|
||||
playEffect: function (filePath, loop) {
|
||||
var effect = this._effect;
|
||||
return this.play(filePath, loop || false, effect.volume);
|
||||
playEffect: function (clip, loop) {
|
||||
return this.play(clip, loop || false, this._effect.volume);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -644,8 +666,8 @@ var audioEngine = {
|
||||
* cc.audioEngine.setEffectsVolume(0.5);
|
||||
*/
|
||||
setEffectsVolume: function (volume) {
|
||||
var musicId = this._music.id;
|
||||
this._effect.volume = volume;
|
||||
var id2audio = audioEngine._id2audio;
|
||||
for (var id in id2audio) {
|
||||
if (id === musicId) continue;
|
||||
audioEngine.setVolume(id, volume);
|
||||
@@ -686,7 +708,6 @@ var audioEngine = {
|
||||
pauseAllEffects: function () {
|
||||
var musicId = this._music.id;
|
||||
var effect = this._effect;
|
||||
var id2audio = this._id2audio;
|
||||
effect.pauseCache.length = 0;
|
||||
|
||||
for (var id in id2audio) {
|
||||
@@ -721,11 +742,10 @@ var audioEngine = {
|
||||
*/
|
||||
resumeAllEffects: function () {
|
||||
var pauseIDCache = this._effect.pauseCache;
|
||||
var id2audio = this._id2audio;
|
||||
while (pauseIDCache.length > 0) {
|
||||
var id = pauseIDCache.pop();
|
||||
for (var i = 0; i < pauseIDCache.length; ++i) {
|
||||
var id = pauseIDCache[i];
|
||||
var audio = id2audio[id];
|
||||
if (audio && audio.resume)
|
||||
if (audio)
|
||||
audio.resume();
|
||||
}
|
||||
},
|
||||
@@ -751,7 +771,6 @@ var audioEngine = {
|
||||
*/
|
||||
stopAllEffects: function () {
|
||||
var musicId = this._music.id;
|
||||
var id2audio = this._id2audio;
|
||||
for (var id in id2audio) {
|
||||
if (id === musicId) continue;
|
||||
var audio = id2audio[id];
|
||||
|
||||
@@ -37,11 +37,6 @@ exports.removed = function (audioEngine) {
|
||||
exports.deprecated = function (audioEngine) {
|
||||
|
||||
var musicId = -1;
|
||||
var musicPath = 1;
|
||||
var musicLoop = 1;
|
||||
var musicVolume = 1;
|
||||
var effectsVolume = 1;
|
||||
var pauseIDCache = [];
|
||||
js.get(audioEngine, 'rewindMusic', function () {
|
||||
cc.warnID(1400, 'audioEngine.rewindMusic', 'audioEngine.setCurrentTime');
|
||||
return function () {
|
||||
|
||||
@@ -1262,7 +1262,7 @@ var Node = cc.Class({
|
||||
* !#zh 删除之前与同类型,回调,目标或 useCapture 注册的回调。
|
||||
* @method off
|
||||
* @param {String} type - A string representing the event type being removed.
|
||||
* @param {Function} callback - The callback to remove.
|
||||
* @param {Function} [callback] - The callback to remove.
|
||||
* @param {Object} [target] - The target (this object) to invoke the callback, if it's not given, only callback without target will be removed
|
||||
* @param {Boolean} [useCapture=false] - Specifies whether the callback being removed was registered as a capturing callback or not.
|
||||
* If not specified, useCapture defaults to false. If a callback was registered twice,
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var RawAsset = require('./CCRawAsset');
|
||||
const RawAsset = require('./CCRawAsset');
|
||||
|
||||
/**
|
||||
* !#en
|
||||
@@ -50,6 +50,19 @@ var RawAsset = require('./CCRawAsset');
|
||||
cc.Asset = cc.Class({
|
||||
name: 'cc.Asset', extends: RawAsset,
|
||||
|
||||
ctor () {
|
||||
/**
|
||||
* !#en
|
||||
* Whether the asset is loaded or not
|
||||
* !#zh
|
||||
* 该资源是否已经成功加载
|
||||
*
|
||||
* @property loaded
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.loaded = true;
|
||||
},
|
||||
|
||||
properties: {
|
||||
/**
|
||||
* !#en
|
||||
@@ -63,9 +76,14 @@ cc.Asset = cc.Class({
|
||||
nativeUrl: {
|
||||
get: function () {
|
||||
if (this._native) {
|
||||
var name = this._native;
|
||||
if (name.charCodeAt(0) === 47) { // '/'
|
||||
// remove library tag
|
||||
// not imported in library, just created on-the-fly
|
||||
return name.slice(1);
|
||||
}
|
||||
if (cc.AssetLibrary) {
|
||||
var base = cc.AssetLibrary.getLibUrlNoExt(this._uuid);
|
||||
var name = this._native;
|
||||
if (name.charCodeAt(0) === 46) { // '.'
|
||||
// imported in dir where json exist
|
||||
return base + name;
|
||||
@@ -92,11 +110,6 @@ cc.Asset = cc.Class({
|
||||
*/
|
||||
_native: "",
|
||||
|
||||
// __nativeAsset: {
|
||||
// default: null,
|
||||
// serializable: false
|
||||
// },
|
||||
|
||||
/**
|
||||
* The underlying native asset of this asset if one is available.
|
||||
* This property can be used to access additional details or functionality releated to the asset.
|
||||
@@ -106,18 +119,8 @@ cc.Asset = cc.Class({
|
||||
* @private
|
||||
*/
|
||||
_nativeAsset: {
|
||||
get () {
|
||||
if (CC_EDITOR) {
|
||||
cc.errorID('0100', 'getter of ' + JS.getClassName(this) + '._nativeAsset');
|
||||
}
|
||||
// return this.__nativeAsset;
|
||||
},
|
||||
set (obj) {
|
||||
if (CC_EDITOR) {
|
||||
cc.errorID('0100', 'setter of ' + JS.getClassName(this) + '._nativeAsset');
|
||||
}
|
||||
// this.__nativeAsset = obj;
|
||||
}
|
||||
get () {},
|
||||
set (obj) {}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -156,6 +159,20 @@ cc.Asset = cc.Class({
|
||||
preventPreloadNativeObject: false
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the asset's url.
|
||||
*
|
||||
* The `Asset` object overrides the `toString()` method of the `Object` object.
|
||||
* For `Asset` objects, the toString() method returns a string representation of the object.
|
||||
* JavaScript calls the toString() method automatically when an asset is to be represented as a text value or when a texture is referred to in a string concatenation.
|
||||
*
|
||||
* @method toString
|
||||
* @return {String}
|
||||
*/
|
||||
toString () {
|
||||
return this.nativeUrl;
|
||||
},
|
||||
|
||||
/**
|
||||
* 应 AssetDB 要求提供这个方法
|
||||
*
|
||||
@@ -188,10 +205,16 @@ cc.Asset = cc.Class({
|
||||
*
|
||||
* @method _setRawAsset
|
||||
* @param {String} filename
|
||||
* @param {Boolean} [inLibrary=true]
|
||||
* @private
|
||||
*/
|
||||
_setRawAsset: function (filename) {
|
||||
this._native = filename || undefined;
|
||||
_setRawAsset: function (filename, inLibrary) {
|
||||
if (inLibrary !== false) {
|
||||
this._native = filename || undefined;
|
||||
}
|
||||
else {
|
||||
this._native = '/' + filename; // simply use '/' to tag location where is not in the library
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -24,17 +24,93 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const Asset = require('./CCAsset');
|
||||
const EventTarget = require('../event/event-target');
|
||||
|
||||
var LoadMode = cc.Enum({
|
||||
WEB_AUDIO: 0,
|
||||
DOM_AUDIO: 1,
|
||||
});
|
||||
|
||||
/**
|
||||
* !#en Class for audio data handling.
|
||||
* !#zh 音频资源类。
|
||||
* @class AudioClip
|
||||
* @extends RawAsset
|
||||
*
|
||||
* @extends Asset
|
||||
* @uses EventTarget
|
||||
*/
|
||||
var AudioClip = cc.Class({
|
||||
name: 'cc.AudioClip',
|
||||
extends: cc.RawAsset,
|
||||
extends: Asset,
|
||||
mixins: [EventTarget],
|
||||
|
||||
ctor () {
|
||||
this.loaded = false;
|
||||
|
||||
// the web audio buffer or <audio> element
|
||||
this._audio = null;
|
||||
},
|
||||
|
||||
properties: {
|
||||
loadMode: {
|
||||
default: LoadMode.WEB_AUDIO,
|
||||
type: LoadMode
|
||||
},
|
||||
_nativeAsset: {
|
||||
get () {
|
||||
return this._audio;
|
||||
},
|
||||
set (value) {
|
||||
this._audio = value;
|
||||
if (value) {
|
||||
this.loaded = true;
|
||||
this.emit('load');
|
||||
}
|
||||
},
|
||||
override: true
|
||||
}
|
||||
},
|
||||
|
||||
statics: {
|
||||
LoadMode: LoadMode,
|
||||
_loadByUrl: function (url, callback) {
|
||||
var item = cc.loader.getItem(url) || cc.loader.getItem(url + '?useDom=1');
|
||||
if (!item || !item.complete) {
|
||||
cc.loader.load(url, function (error, downloadUrl) {
|
||||
if (error) {
|
||||
return callback(error);
|
||||
}
|
||||
item = cc.loader.getItem(url) || cc.loader.getItem(url + '?useDom=1');
|
||||
callback(null, item.content);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (item._owner instanceof AudioClip) {
|
||||
// preloaded and retained by audio clip
|
||||
callback(null, item._owner);
|
||||
}
|
||||
else {
|
||||
callback(null, item.content);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
destroy () {
|
||||
cc.audioEngine.uncache(this);
|
||||
this._super();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* !#zh
|
||||
* 当该资源加载成功后触发该事件
|
||||
* !#en
|
||||
* This event is emitted when the asset is loaded
|
||||
*
|
||||
* @event load
|
||||
* @param {Event.EventCustom} event
|
||||
*/
|
||||
|
||||
cc.AudioClip = AudioClip;
|
||||
module.exports = AudioClip;
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @module cc
|
||||
*/
|
||||
/**
|
||||
* !#en Class for Font handling.
|
||||
* !#zh 字体资源类。
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
* to specify how to optimize the instantiate operation.
|
||||
*
|
||||
* @enum Prefab.OptimizationPolicy
|
||||
* @since 1.8.0
|
||||
* @since 1.10.0
|
||||
*/
|
||||
var OptimizationPolicy = cc.Enum({
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ var Prefab = cc.Class({
|
||||
*
|
||||
* @property {Prefab.OptimizationPolicy} optimizationPolicy
|
||||
* @default Prefab.OptimizationPolicy.AUTO
|
||||
* @since 1.8.0
|
||||
* @since 1.10.0
|
||||
* @example
|
||||
* prefab.optimizationPolicy = cc.Prefab.OptimizationPolicy.MULTI_INSTANCE;
|
||||
*/
|
||||
|
||||
@@ -30,13 +30,8 @@ var JS = require('../platform/js');
|
||||
/**
|
||||
* !#en
|
||||
* The base class for registering asset types.
|
||||
*
|
||||
* You may want to override:
|
||||
* - createNode (static)
|
||||
* !#zh
|
||||
* 注册用的资源基类。<br/>
|
||||
* 你可能要重写:<br/>
|
||||
* - createNode (static)
|
||||
* 注册用的资源基类。
|
||||
*
|
||||
* @class RawAsset
|
||||
* @extends Object
|
||||
@@ -56,24 +51,6 @@ cc.RawAsset = cc.Class({
|
||||
// enumerable is false by default, to avoid uuid being assigned to empty string during destroy
|
||||
});
|
||||
},
|
||||
|
||||
statics: {
|
||||
/**
|
||||
* !#en
|
||||
* Create a new node in the scene.<br/>
|
||||
* If this type of asset dont have its corresponding node type, this method should be null.
|
||||
* !#zh
|
||||
* 在场景中创建一个新节点。<br/>
|
||||
* 如果这类资源没有相应的节点类型,该方法应该是空的。
|
||||
* @method createNodeByInfo
|
||||
* @param {Object} Info
|
||||
* @param {Function} callback
|
||||
* @param {String} callback.error - null or the error info
|
||||
* @param {Object} callback.node - the created node or null
|
||||
* @static
|
||||
*/
|
||||
createNodeByInfo: null,
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -89,7 +66,10 @@ JS.value(cc.RawAsset, 'isRawAssetType', function (ctor) {
|
||||
|
||||
// TODO - DELME after 2.0
|
||||
JS.value(cc.RawAsset, 'wasRawAssetType', function (ctor) {
|
||||
return ctor === cc.Texture2D;
|
||||
return ctor === cc.Texture2D ||
|
||||
ctor === cc.AudioClip ||
|
||||
ctor === cc.ParticleAsset ||
|
||||
ctor === cc.Asset; // since 1.10, all raw asset will import as cc.Asset
|
||||
});
|
||||
|
||||
module.exports = cc.RawAsset;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
* !#zh 精灵图集资源类。
|
||||
* @class SpriteAtlas
|
||||
* @extends Asset
|
||||
*
|
||||
*/
|
||||
var SpriteAtlas = cc.Class({
|
||||
name: 'cc.SpriteAtlas',
|
||||
|
||||
@@ -29,11 +29,20 @@
|
||||
* !#zh 文本资源类。
|
||||
* @class TextAsset
|
||||
* @extends Asset
|
||||
*
|
||||
*/
|
||||
var TextAsset = cc.Class({
|
||||
name: 'cc.TextAsset',
|
||||
extends: cc.Asset,
|
||||
properties: {
|
||||
/**
|
||||
* @property {String} text - The text contents of the resource.
|
||||
*/
|
||||
text: "",
|
||||
},
|
||||
|
||||
toString () {
|
||||
return this.text;
|
||||
},
|
||||
});
|
||||
|
||||
cc.TextAsset = TextAsset;
|
||||
module.exports = cc.TextAsset = TextAsset;
|
||||
|
||||
@@ -37,4 +37,4 @@ require('./CCTTFFont');
|
||||
require('./CCSpriteAtlas');
|
||||
require('./CCBitmapFont');
|
||||
require('./CCLabelAtlas');
|
||||
//require('./CCTextAsset');
|
||||
require('./CCTextAsset');
|
||||
|
||||
@@ -552,7 +552,7 @@ var Animation = cc.Class({
|
||||
* 取消注册动画事件回调。
|
||||
* @method off
|
||||
* @param {String} type - A string representing the event type being removed.
|
||||
* @param {Function} callback - The callback to remove.
|
||||
* @param {Function} [callback] - The callback to remove.
|
||||
* @param {Object} [target] - The target (this object) to invoke the callback, if it's not given, only callback without target will be removed
|
||||
* @param {Boolean} [useCapture=false] - Specifies whether the callback being removed was registered as a capturing callback or not.
|
||||
* If not specified, useCapture defaults to false. If a callback was registered twice,
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const AudioClip = require('../assets/CCAudioClip');
|
||||
require('../../audio/CCAudio');
|
||||
|
||||
/**
|
||||
* !#en Audio Source.
|
||||
* !#zh 音频源组件,能对音频剪辑。
|
||||
@@ -47,8 +50,8 @@ var AudioSource = cc.Class({
|
||||
|
||||
properties: {
|
||||
_clip: {
|
||||
default: '',
|
||||
url: cc.AudioClip
|
||||
default: null,
|
||||
type: AudioClip
|
||||
},
|
||||
_volume: 1,
|
||||
_mute: false,
|
||||
@@ -72,7 +75,6 @@ var AudioSource = cc.Class({
|
||||
*/
|
||||
isPlaying: {
|
||||
get: function () {
|
||||
if (!this.audio) return false;
|
||||
var state = this.audio.getState();
|
||||
return state === cc.Audio.State.PLAYING;
|
||||
},
|
||||
@@ -80,8 +82,8 @@ var AudioSource = cc.Class({
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en The clip of the audio source.
|
||||
* !#zh 默认要播放的音频剪辑。
|
||||
* !#en The clip of the audio source to play.
|
||||
* !#zh 要播放的音频剪辑。
|
||||
* @property clip
|
||||
* @type {AudioClip}
|
||||
* @default 1
|
||||
@@ -91,17 +93,28 @@ var AudioSource = cc.Class({
|
||||
return this._clip;
|
||||
},
|
||||
set: function (value) {
|
||||
if (typeof value === 'string') {
|
||||
// backward compatibility since 1.10
|
||||
cc.warnID(8401, 'cc.AudioSource');
|
||||
let self = this;
|
||||
AudioClip._loadByUrl(value, function (err, clip) {
|
||||
if (clip) {
|
||||
self.clip = clip;
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (value === this._clip) {
|
||||
return;
|
||||
}
|
||||
this._clip = value;
|
||||
this.audio.stop();
|
||||
this.audio.src = this._clip;
|
||||
if (this.audio.preload) {
|
||||
this.audio.preload();
|
||||
if (this.preload) {
|
||||
this.audio.src = this._clip;
|
||||
}
|
||||
},
|
||||
url: cc.AudioClip,
|
||||
type: AudioClip,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.audio.clip',
|
||||
animatable: false
|
||||
},
|
||||
@@ -120,14 +133,8 @@ var AudioSource = cc.Class({
|
||||
set: function (value) {
|
||||
value = cc.clamp01(value);
|
||||
this._volume = value;
|
||||
var audio = this.audio;
|
||||
if (audio && !this._mute) {
|
||||
audio.setVolume(value);
|
||||
if (!audio._loaded) {
|
||||
audio.on('load', function () {
|
||||
audio.setVolume(value);
|
||||
});
|
||||
}
|
||||
if (!this._mute) {
|
||||
this.audio.setVolume(value);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
@@ -147,9 +154,7 @@ var AudioSource = cc.Class({
|
||||
},
|
||||
set: function (value) {
|
||||
this._mute = value;
|
||||
if (this.audio) {
|
||||
this.audio.setVolume(value ? 0 : this._volume);
|
||||
}
|
||||
this.audio.setVolume(value ? 0 : this._volume);
|
||||
return value;
|
||||
},
|
||||
animatable: false,
|
||||
@@ -169,9 +174,7 @@ var AudioSource = cc.Class({
|
||||
},
|
||||
set: function (value) {
|
||||
this._loop = value;
|
||||
if (this.audio) {
|
||||
this.audio.setLoop(value);
|
||||
}
|
||||
this.audio.setLoop(value);
|
||||
return value;
|
||||
},
|
||||
animatable: false,
|
||||
@@ -179,8 +182,8 @@ var AudioSource = cc.Class({
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en If set to true, the audio source will automatically start playing on onLoad.
|
||||
* !#zh 如果设置为true,音频源将在 onLoad 时自动播放。
|
||||
* !#en If set to true, the audio source will automatically start playing on onEnable.
|
||||
* !#zh 如果设置为 true,音频源将在 onEnable 时自动播放。
|
||||
* @property playOnLoad
|
||||
* @type {Boolean}
|
||||
* @default true
|
||||
@@ -197,28 +200,37 @@ var AudioSource = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
_ensureDataLoaded () {
|
||||
if (this.audio.src !== this._clip) {
|
||||
this.audio.src = this._clip;
|
||||
}
|
||||
},
|
||||
|
||||
_pausedCallback: function () {
|
||||
var audio = this.audio;
|
||||
if (!audio || audio.paused) return;
|
||||
if (audio.paused) return;
|
||||
this.audio.pause();
|
||||
this._pausedFlag = true;
|
||||
},
|
||||
|
||||
_restoreCallback: function () {
|
||||
if (!this.audio) return;
|
||||
if (this._pausedFlag) {
|
||||
this.audio.resume();
|
||||
}
|
||||
this._pausedFlag = false;
|
||||
},
|
||||
|
||||
onLoad: function () {
|
||||
this.audio.setVolume(this._mute ? 0 : this._volume);
|
||||
this.audio.setLoop(this._loop);
|
||||
},
|
||||
|
||||
onEnable: function () {
|
||||
if ( this.playOnLoad ) {
|
||||
this.play();
|
||||
}
|
||||
if ( this.preload ) {
|
||||
if (this.preload) {
|
||||
this.audio.src = this._clip;
|
||||
this.audio.preload();
|
||||
}
|
||||
if (this.playOnLoad) {
|
||||
this.play();
|
||||
}
|
||||
cc.game.on(cc.game.EVENT_HIDE, this._pausedCallback, this);
|
||||
cc.game.on(cc.game.EVENT_SHOW, this._restoreCallback, this);
|
||||
@@ -243,24 +255,13 @@ var AudioSource = cc.Class({
|
||||
play: function () {
|
||||
if ( !this._clip ) return;
|
||||
|
||||
var volume = this._mute ? 0 : this._volume;
|
||||
var audio = this.audio;
|
||||
var loop = this._loop;
|
||||
|
||||
if (audio._loaded) {
|
||||
if (this._clip.loaded) {
|
||||
audio.stop();
|
||||
audio.setCurrentTime(0);
|
||||
audio.play();
|
||||
return;
|
||||
}
|
||||
|
||||
audio.src = this._clip;
|
||||
audio.once('load', function () {
|
||||
audio.setLoop(loop);
|
||||
audio.setVolume(volume);
|
||||
audio.play();
|
||||
});
|
||||
audio.preload();
|
||||
this._ensureDataLoaded();
|
||||
audio.setCurrentTime(0);
|
||||
audio.play();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -269,9 +270,7 @@ var AudioSource = cc.Class({
|
||||
* @method stop
|
||||
*/
|
||||
stop: function () {
|
||||
if (this.audio) {
|
||||
this.audio.stop();
|
||||
}
|
||||
this.audio.stop();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -280,9 +279,7 @@ var AudioSource = cc.Class({
|
||||
* @method pause
|
||||
*/
|
||||
pause: function () {
|
||||
if (this.audio) {
|
||||
this.audio.pause();
|
||||
}
|
||||
this.audio.pause();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -291,9 +288,8 @@ var AudioSource = cc.Class({
|
||||
* @method resume
|
||||
*/
|
||||
resume: function () {
|
||||
if (this.audio) {
|
||||
this.audio.resume();
|
||||
}
|
||||
this._ensureDataLoaded();
|
||||
this.audio.resume();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -302,9 +298,7 @@ var AudioSource = cc.Class({
|
||||
* @method rewind
|
||||
*/
|
||||
rewind: function(){
|
||||
if (this.audio) {
|
||||
this.audio.setCurrentTime(0);
|
||||
}
|
||||
this.audio.setCurrentTime(0);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -313,11 +307,7 @@ var AudioSource = cc.Class({
|
||||
* @method getCurrentTime
|
||||
*/
|
||||
getCurrentTime: function () {
|
||||
var time = 0;
|
||||
if (this.audio) {
|
||||
time = this.audio.getCurrentTime();
|
||||
}
|
||||
return time;
|
||||
return this.audio.getCurrentTime();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -327,16 +317,7 @@ var AudioSource = cc.Class({
|
||||
* @param {Number} time
|
||||
*/
|
||||
setCurrentTime: function (time) {
|
||||
var audio = this.audio;
|
||||
if (!audio) return time;
|
||||
|
||||
if (!audio._loaded) {
|
||||
audio.once('load', function () {
|
||||
audio.setCurrentTime(time);
|
||||
});
|
||||
return time;
|
||||
}
|
||||
audio.setCurrentTime(time);
|
||||
this.audio.setCurrentTime(time);
|
||||
return time;
|
||||
},
|
||||
|
||||
@@ -346,11 +327,7 @@ var AudioSource = cc.Class({
|
||||
* @method getDuration
|
||||
*/
|
||||
getDuration: function () {
|
||||
var time = 0;
|
||||
if (this.audio) {
|
||||
time = this.audio.getDuration();
|
||||
}
|
||||
return time;
|
||||
return this.audio.getDuration();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -142,7 +142,7 @@ var VideoPlayer = cc.Class({
|
||||
|
||||
_clip: {
|
||||
default: null,
|
||||
url: cc.RawAsset
|
||||
type: cc.Asset
|
||||
},
|
||||
/**
|
||||
* !#en The local video full path.
|
||||
@@ -160,7 +160,7 @@ var VideoPlayer = cc.Class({
|
||||
this._clip = value;
|
||||
this._updateVideoSource();
|
||||
},
|
||||
url: cc.RawAsset
|
||||
type: cc.Asset
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -305,7 +305,7 @@ var VideoPlayer = cc.Class({
|
||||
sgNode.setURL(this.remoteURL);
|
||||
}
|
||||
else {
|
||||
sgNode.setURL(this._clip || '');
|
||||
sgNode.setURL(this._clip.nativeUrl || '');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ var ReleasedAssetChecker = CC_DEBUG && require('./released-asset-checker');
|
||||
|
||||
var resources = new AssetTable();
|
||||
|
||||
var AUDIO_TYPES = ['mp3', 'ogg', 'wav', 'm4a'];
|
||||
|
||||
function getXMLHttpRequest () {
|
||||
return window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP');
|
||||
}
|
||||
@@ -769,14 +767,10 @@ proto.release = function (asset) {
|
||||
asset = item.content;
|
||||
if (cc.Class.isInstanceOf(asset, cc.Asset)) {
|
||||
if (asset.nativeUrl) {
|
||||
this.release(asset.nativeUrl);
|
||||
this.release(asset.nativeUrl); // uncache loading item of native asset
|
||||
}
|
||||
asset.destroy();
|
||||
}
|
||||
else if (AUDIO_TYPES.indexOf(item.type) !== -1) {
|
||||
// TODO: use asset.destroy
|
||||
cc.audioEngine.uncache(item.rawUrl || item.url);
|
||||
}
|
||||
if (CC_DEBUG && removed) {
|
||||
this._releasedAssetChecker_DEBUG.setReleased(item, id);
|
||||
}
|
||||
|
||||
@@ -24,10 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Path = require('../utils/CCPath');
|
||||
var sys = require('../platform/CCSys');
|
||||
var Pipeline = require('./pipeline');
|
||||
var audioEngine = require('../../audio/CCAudioEngine');
|
||||
|
||||
var __audioSupport = sys.__audioSupport;
|
||||
var formatSupport = __audioSupport.format;
|
||||
@@ -37,9 +34,8 @@ function loadDomAudio (item, callback) {
|
||||
var dom = document.createElement('audio');
|
||||
dom.src = item.url;
|
||||
|
||||
if (sys.platform === sys.WECHAT_GAME) {
|
||||
item.element = dom;
|
||||
callback(null, item.url);
|
||||
if (CC_WECHATGAME) {
|
||||
callback(null, dom);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,14 +54,13 @@ function loadDomAudio (item, callback) {
|
||||
}, 8000);
|
||||
var success = function () {
|
||||
clearEvent();
|
||||
item.element = dom;
|
||||
callback(null, item.url);
|
||||
callback(null, dom);
|
||||
};
|
||||
var failure = function () {
|
||||
clearEvent();
|
||||
var message = 'load audio failure - ' + item.url;
|
||||
cc.log(message);
|
||||
callback(message, item.url);
|
||||
callback(message);
|
||||
};
|
||||
dom.addEventListener("canplaythrough", success, false);
|
||||
dom.addEventListener("error", failure, false);
|
||||
@@ -84,8 +79,7 @@ function loadWebAudio (item, callback) {
|
||||
request.onload = function () {
|
||||
context["decodeAudioData"](request.response, function(buffer){
|
||||
//success
|
||||
item.buffer = buffer;
|
||||
callback(null, item.id);
|
||||
callback(null, buffer);
|
||||
}, function(){
|
||||
//error
|
||||
callback('decode error - ' + item.id, null);
|
||||
@@ -104,15 +98,21 @@ function downloadAudio (item, callback) {
|
||||
return new Error(cc._getError(4927));
|
||||
}
|
||||
|
||||
item.content = item.url;
|
||||
|
||||
// If WebAudio is not supported, load using DOM mode
|
||||
if (!__audioSupport.WEB_AUDIO || (item.urlParam && item.urlParam['useDom'])) {
|
||||
loadDomAudio(item, callback);
|
||||
var loader;
|
||||
if (!__audioSupport.WEB_AUDIO) {
|
||||
// If WebAudio is not supported, load using DOM mode
|
||||
loader = loadDomAudio;
|
||||
}
|
||||
else {
|
||||
loadWebAudio(item, callback);
|
||||
var loadByDeserializedAudio = item._owner instanceof cc.AudioClip;
|
||||
if (loadByDeserializedAudio) {
|
||||
loader = (item._owner.loadMode === cc.AudioClip.LoadMode.WEB_AUDIO) ? loadWebAudio : loadDomAudio;
|
||||
}
|
||||
else {
|
||||
loader = (item.urlParam && item.urlParam['useDom']) ? loadDomAudio : loadWebAudio;
|
||||
}
|
||||
}
|
||||
loader(item, callback);
|
||||
}
|
||||
|
||||
module.exports = downloadAudio;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
var JS = require('../platform/js');
|
||||
var sys = require('../platform/CCSys');
|
||||
var Pipeline = require('./pipeline');
|
||||
var Texture2D = require('../textures/CCTexture2D');
|
||||
var loadUuid = require('./uuid-loader');
|
||||
@@ -49,8 +48,14 @@ function loadJSON (item, callback) {
|
||||
}
|
||||
|
||||
function loadImage (item, callback) {
|
||||
var loadByDeserializedAsset = item._owner instanceof cc.Asset;
|
||||
if (loadByDeserializedAsset) {
|
||||
// already has cc.Asset
|
||||
return null;
|
||||
}
|
||||
|
||||
var image = item.content;
|
||||
if (sys.platform !== sys.WECHAT_GAME && sys.platform !== sys.QQ_PLAY && !(image instanceof Image)) {
|
||||
if (!CC_WECHATGAME && !CC_QQPLAY && !(image instanceof Image)) {
|
||||
return new Error('Image Loader: Input item doesn\'t contain Image content');
|
||||
}
|
||||
|
||||
@@ -58,11 +63,27 @@ function loadImage (item, callback) {
|
||||
var rawUrl = item.rawUrl;
|
||||
var tex = cc.textureCache.getTextureForKey(rawUrl) || new Texture2D();
|
||||
tex.url = rawUrl;
|
||||
tex._setRawAsset(rawUrl, false);
|
||||
tex._nativeAsset = image;
|
||||
cc.textureCache.cacheImage(rawUrl, tex);
|
||||
return tex;
|
||||
}
|
||||
|
||||
// If audio is loaded by url directly, than this loader will wrap it into a new cc.AudioClip object.
|
||||
// If audio is loaded by deserialized AudioClip, than this loader will be skipped.
|
||||
function loadAudioAsAsset (item, callback) {
|
||||
var loadByDeserializedAsset = item._owner instanceof cc.Asset;
|
||||
if (loadByDeserializedAsset) {
|
||||
// already has cc.Asset
|
||||
return null;
|
||||
}
|
||||
|
||||
var audioClip = new cc.AudioClip();
|
||||
audioClip._setRawAsset(item.rawUrl, false);
|
||||
audioClip._nativeAsset = item.content;
|
||||
return audioClip;
|
||||
}
|
||||
|
||||
function loadPlist (item, callback) {
|
||||
if (typeof item.content !== 'string') {
|
||||
return new Error('Plist Loader: Input item doesn\'t contain string content');
|
||||
@@ -89,6 +110,12 @@ var defaultMap = {
|
||||
'webp' : loadImage,
|
||||
'image' : loadImage,
|
||||
|
||||
// Audio
|
||||
'mp3' : loadAudioAsAsset,
|
||||
'ogg' : loadAudioAsAsset,
|
||||
'wav' : loadAudioAsAsset,
|
||||
'm4a' : loadAudioAsAsset,
|
||||
|
||||
'json' : loadJSON,
|
||||
'ExportJson' : loadJSON,
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ module.exports = {
|
||||
//},
|
||||
urlAppendTimestamp: function (url) {
|
||||
if (cc.game.config['noCache'] && typeof url === 'string') {
|
||||
if(_noCacheRex.test(url))
|
||||
if (_noCacheRex.test(url))
|
||||
url += '&_t=' + (new Date() - 0);
|
||||
else
|
||||
url += '?_t=' + (new Date() - 0);
|
||||
|
||||
@@ -58,7 +58,6 @@ function parseDepends (item, asset, tdInfo, deferredLoadRawAssetsInRuntime) {
|
||||
var info = cc.AssetLibrary._getAssetInfoInRuntime(dependUuid);
|
||||
if (info.raw) {
|
||||
// skip preloading raw assets
|
||||
// TODO - skip preloading native texture
|
||||
var url = info.url;
|
||||
obj[prop] = url;
|
||||
dependKeys.push(url);
|
||||
@@ -91,12 +90,10 @@ function parseDepends (item, asset, tdInfo, deferredLoadRawAssetsInRuntime) {
|
||||
};
|
||||
}
|
||||
|
||||
// parse native
|
||||
// load native object (Image/Audio) as depends
|
||||
if (asset._native && !asset.constructor.preventPreloadNativeObject) {
|
||||
depends.push({
|
||||
url: asset.nativeUrl,
|
||||
// For image, we should skip loader otherwise it will load a new texture
|
||||
skips: [ 'Loader' ],
|
||||
_owner: asset,
|
||||
_ownerProp: '_nativeAsset',
|
||||
});
|
||||
@@ -112,8 +109,9 @@ function loadDepends (pipeline, item, asset, depends, callback) {
|
||||
var dependKeys = item.dependKeys;
|
||||
pipeline.flowInDeps(item, depends, function (errors, items) {
|
||||
var item, missingAssetReporter;
|
||||
for (var src in items.map) {
|
||||
item = items.map[src];
|
||||
var itemsMap = items.map;
|
||||
for (var src in itemsMap) {
|
||||
item = itemsMap[src];
|
||||
if (item.uuid && item.content) {
|
||||
item.content._uuid = item.uuid;
|
||||
}
|
||||
@@ -124,50 +122,50 @@ function loadDepends (pipeline, item, asset, depends, callback) {
|
||||
var dependUrl = dep.url;
|
||||
var dependObj = dep._owner;
|
||||
var dependProp = dep._ownerProp;
|
||||
item = items.map[dependUrl];
|
||||
if (item) {
|
||||
var thisOfLoadCallback = dep;
|
||||
function loadCallback (item) {
|
||||
var value;
|
||||
if (this._stillUseUrl) {
|
||||
value = (item.content instanceof cc.Texture2D) ? item.content.nativeUrl : item.rawUrl
|
||||
}
|
||||
else {
|
||||
value = item.content;
|
||||
}
|
||||
this._owner[this._ownerProp] = value;
|
||||
if (item.uuid !== asset._uuid && dependKeys.indexOf(item.id) < 0) {
|
||||
dependKeys.push(item.id);
|
||||
}
|
||||
item = itemsMap[dependUrl];
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var loadCallbackCtx = dep;
|
||||
function loadCallback (item) {
|
||||
var value = item.content;
|
||||
if (this._stillUseUrl) {
|
||||
value = (value && cc.RawAsset.wasRawAssetType(value.constructor)) ? value.nativeUrl : item.rawUrl;
|
||||
}
|
||||
if (item.complete || item.content) {
|
||||
if (item.error) {
|
||||
if (CC_EDITOR && item.error.errorCode === 'db.NOTFOUND') {
|
||||
if (!missingAssetReporter) {
|
||||
var MissingObjectReporter = Editor.require('app://editor/page/scene-utils/missing-object-reporter');
|
||||
missingAssetReporter = new MissingObjectReporter(asset);
|
||||
}
|
||||
missingAssetReporter.stashByOwner(dependObj, dependProp, Editor.serialize.asAsset(dependSrc));
|
||||
}
|
||||
else {
|
||||
cc._throw(item.error);
|
||||
this._owner[this._ownerProp] = value;
|
||||
if (item.uuid !== asset._uuid && dependKeys.indexOf(item.id) < 0) {
|
||||
dependKeys.push(item.id);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.complete || item.content) {
|
||||
if (item.error) {
|
||||
if (CC_EDITOR && item.error.errorCode === 'db.NOTFOUND') {
|
||||
if (!missingAssetReporter) {
|
||||
var MissingObjectReporter = Editor.require('app://editor/page/scene-utils/missing-object-reporter');
|
||||
missingAssetReporter = new MissingObjectReporter(asset);
|
||||
}
|
||||
missingAssetReporter.stashByOwner(dependObj, dependProp, Editor.serialize.asAsset(dependSrc));
|
||||
}
|
||||
else {
|
||||
loadCallback.call(thisOfLoadCallback, item);
|
||||
cc._throw(item.error);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// item was removed from cache, but ready in pipeline actually
|
||||
var queue = LoadingItems.getQueue(item);
|
||||
// Hack to get a better behavior
|
||||
var list = queue._callbackTable[dependSrc];
|
||||
if (list) {
|
||||
list.unshift(loadCallback, thisOfLoadCallback);
|
||||
}
|
||||
else {
|
||||
queue.addListener(dependSrc, loadCallback, thisOfLoadCallback);
|
||||
}
|
||||
loadCallback.call(loadCallbackCtx, item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// item was removed from cache, but ready in pipeline actually
|
||||
var queue = LoadingItems.getQueue(item);
|
||||
// Hack to get a better behavior
|
||||
var list = queue._callbackTable[dependSrc];
|
||||
if (list) {
|
||||
list.unshift(loadCallback, loadCallbackCtx);
|
||||
}
|
||||
else {
|
||||
queue.addListener(dependSrc, loadCallback, loadCallbackCtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -555,7 +555,7 @@ function getInitProps (attrs, propList) {
|
||||
}
|
||||
|
||||
// simple test variable name
|
||||
var IDENTIFIER_RE = /^[$A-Za-z_][0-9A-Za-z_$]*$/;
|
||||
var IDENTIFIER_RE = /^[A-Za-z_$][0-9A-Za-z_$]*$/;
|
||||
function compileProps (actualClass) {
|
||||
// init deferred properties
|
||||
var attrs = Attr.getClassAttrs(actualClass);
|
||||
|
||||
@@ -99,8 +99,54 @@ function checkUrl (val, className, propName, url) {
|
||||
if (typeof url !== 'function' || !cc.isChildClassOf(url, cc.RawAsset)) {
|
||||
return cc.errorID(5504, className, propName);
|
||||
}
|
||||
if (cc.isChildClassOf(url, cc.Asset) && !cc.RawAsset.wasRawAssetType(url)) {
|
||||
return cc.errorID(5505, className, propName, cc.js.getClassName(url));
|
||||
if (url === cc.RawAsset) {
|
||||
cc.warn('Please change the definition of property \'%s\' in class \'%s\'. Starting from v1.10,\n' +
|
||||
'the use of declaring a property in CCClass as a URL has been deprecated.\n' +
|
||||
'For example, if property is cc.RawAsset, the previous definition is:\n' +
|
||||
' %s: cc.RawAsset,\n' +
|
||||
' // or:\n' +
|
||||
' %s: {\n' +
|
||||
' url: cc.RawAsset,\n' +
|
||||
' default: ""\n' +
|
||||
' },\n' +
|
||||
' // and the original method to get url is:\n' +
|
||||
' `this.%s`\n' +
|
||||
'Now it should be changed to:\n' +
|
||||
' %s: {\n' +
|
||||
' type: cc.Asset, // use \'type:\' to define Asset object directly\n' +
|
||||
' default: null, // object\'s default value is null\n' +
|
||||
' },\n' +
|
||||
' // and you must get the url by using:\n' +
|
||||
' `this.%s.nativeUrl`\n' +
|
||||
'(This helps us to successfully refactor all RawAssets at v2.0, ' +
|
||||
'sorry for the inconvenience. \uD83D\uDE30 )',
|
||||
propName, className, propName, propName, propName, propName, propName);
|
||||
}
|
||||
else if (cc.isChildClassOf(url, cc.Asset)) {
|
||||
if (cc.RawAsset.wasRawAssetType(url)) {
|
||||
if (!val._short) {
|
||||
cc.warn('Please change the definition of property \'%s\' in class \'%s\'. Starting from v1.10,\n' +
|
||||
'the use of declaring a property in CCClass as a URL has been deprecated.\n' +
|
||||
'For example, if property is Texture2D, the previous definition is:\n' +
|
||||
' %s: cc.Texture2D,\n' +
|
||||
' // or:\n' +
|
||||
' %s: {\n' +
|
||||
' url: cc.Texture2D,\n' +
|
||||
' default: ""\n' +
|
||||
' },\n' +
|
||||
'Now it should be changed to:\n' +
|
||||
' %s: {\n' +
|
||||
' type: cc.Texture2D, // use \'type:\' to define Texture2D object directly\n' +
|
||||
' default: null, // object\'s default value is null\n' +
|
||||
' },\n' +
|
||||
'(This helps us to successfully refactor all RawAssets at v2.0, ' +
|
||||
'sorry for the inconvenience. \uD83D\uDE30 )',
|
||||
propName, className, propName, propName, propName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return cc.errorID(5505, className, propName, cc.js.getClassName(url));
|
||||
}
|
||||
}
|
||||
if (val.type) {
|
||||
return cc.warnID(5506, className, propName);
|
||||
@@ -174,25 +220,20 @@ exports.getFullFormOfProperty = function (options, propname_dev, classname_dev)
|
||||
if (Array.isArray(options) && options.length > 0) {
|
||||
var type = options[0];
|
||||
if (CC_DEV && cc.RawAsset.wasRawAssetType(type)) {
|
||||
// deprecate `myProp: [cc.Texture2D]` since 1.8
|
||||
cc.warn('Please change the definition of property \'%s\' in class \'%s\'. Starting from v1.8,\n' +
|
||||
// deprecate `myProp: [cc.Texture2D]` since 1.10
|
||||
cc.warn('Please change the definition of property \'%s\' in class \'%s\'. Starting from v1.10,\n' +
|
||||
'properties in CCClass can not be abbreviated if they are of type RawAsset.\n' +
|
||||
'Please use the complete form.\n' +
|
||||
'For example, if property is Texture2D\'s url array, the previous definition is:\n' +
|
||||
' %s: [cc.Texture2D]\n' +
|
||||
'now it should be changed to:\n' +
|
||||
' %s: {\n' +
|
||||
' url: cc.Texture2D, // use \'url:\' to define a url array for Texture2D\n' +
|
||||
' default: []\n' +
|
||||
' }\n' +
|
||||
'or more preferably:\n' +
|
||||
' %s: [cc.Texture2D],\n' +
|
||||
'Now it should be changed to:\n' +
|
||||
' %s: {\n' +
|
||||
' type: cc.Texture2D, // use \'type:\' to define an array of Texture2D objects\n' +
|
||||
' default: []\n' +
|
||||
' }\n' +
|
||||
' },\n' +
|
||||
'(This helps us to successfully refactor all RawAssets at v2.0, ' +
|
||||
'sorry for the inconvenience. \uD83D\uDE30 )',
|
||||
propname_dev, classname_dev, propname_dev, propname_dev, propname_dev);
|
||||
propname_dev, classname_dev, propname_dev, propname_dev);
|
||||
return {
|
||||
default: [],
|
||||
url: options,
|
||||
@@ -209,26 +250,21 @@ exports.getFullFormOfProperty = function (options, propname_dev, classname_dev)
|
||||
var type = options;
|
||||
if (!cc.RawAsset.isRawAssetType(type)) {
|
||||
if (cc.RawAsset.wasRawAssetType(type)) {
|
||||
// deprecate `myProp: cc.Texture2D` since 1.8
|
||||
// deprecate `myProp: cc.Texture2D` since 1.10
|
||||
if (CC_DEV) {
|
||||
cc.warn('Please change the definition of property \'%s\' in class \'%s\'. Starting from v1.8,\n' +
|
||||
cc.warn('Please change the definition of property \'%s\' in class \'%s\'. Starting from v1.10,\n' +
|
||||
'properties in CCClass can not be abbreviated if they are of type RawAsset.\n' +
|
||||
'Please use the complete form.\n' +
|
||||
'For example, if the type is Texture2D, the previous definition is:\n' +
|
||||
' %s: cc.Texture2D\n' +
|
||||
'now it should be changed to:\n' +
|
||||
' %s: {\n' +
|
||||
' url: cc.Texture2D // use \'url:\' to define url for Texture2D\n' +
|
||||
' default: "", // url\'s default value is empty string\n' +
|
||||
' }\n' +
|
||||
'or more preferably:\n' +
|
||||
' %s: cc.Texture2D,\n' +
|
||||
'Now it should be changed to:\n' +
|
||||
' %s: {\n' +
|
||||
' type: cc.Texture2D // use \'type:\' to define Texture2D object directly\n' +
|
||||
' default: null, // object\'s default value of is null\n' +
|
||||
' }\n' +
|
||||
' default: null, // object\'s default value is null\n' +
|
||||
' },\n' +
|
||||
'(This helps us to successfully refactor all RawAssets at v2.0, ' +
|
||||
'sorry for the inconvenience. \uD83D\uDE30 )',
|
||||
propname_dev, classname_dev, propname_dev, propname_dev, propname_dev);
|
||||
propname_dev, classname_dev, propname_dev, propname_dev);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -87,6 +87,13 @@ cc.url = {
|
||||
cc.errorID(7002, url);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// backward compatibility since 1.10
|
||||
var uuid = cc.loader._getResUuid(url.slice(10), cc.Asset, true);
|
||||
if (uuid) {
|
||||
return cc.AssetLibrary.getLibUrlNoExt(uuid) + cc.path.extname(url);
|
||||
}
|
||||
}
|
||||
|
||||
return this._rawAssets + url;
|
||||
},
|
||||
|
||||
@@ -40,7 +40,6 @@ require('./CCDirectorWebGL');
|
||||
require('./CCDirectorCanvas');
|
||||
|
||||
if (!(CC_EDITOR && Editor.isMainProcess)) {
|
||||
require('./platform/CCSAXParser');
|
||||
require('./platform/CCView');
|
||||
require('./platform/CCScreen');
|
||||
require('./CCScheduler');
|
||||
|
||||
@@ -73,7 +73,7 @@ proto.updateBlendFunc = function (blendFunc) {
|
||||
};
|
||||
|
||||
proto._handleTextureForRotatedTexture = function (texture, rect, rotated, counterclockwise) {
|
||||
if (rotated && texture.isLoaded()) {
|
||||
if (rotated && texture.loaded) {
|
||||
texture = CanvasRenderCmd._createRotatedTexture(texture, rect, counterclockwise);
|
||||
rect.x = rect.y = 0;
|
||||
this._node._rect = cc.rect(0, 0, rect.width, rect.height);
|
||||
|
||||
@@ -174,7 +174,7 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
|
||||
* @returns {boolean}
|
||||
*/
|
||||
textureLoaded: function () {
|
||||
return this._texture && this._texture.isLoaded();
|
||||
return this._texture && this._texture.loaded;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -412,7 +412,7 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
|
||||
*/
|
||||
ensureLoadTexture: function () {
|
||||
if (this._texture) {
|
||||
if (!this._texture.isLoaded()) {
|
||||
if (!this._texture.loaded) {
|
||||
// load exists texture
|
||||
this._refreshTexture(this._texture);
|
||||
this._texture.load();
|
||||
|
||||
@@ -208,16 +208,9 @@ var Texture2D = cc.Class({
|
||||
* @type {String}
|
||||
* @readonly
|
||||
*/
|
||||
// TODO - use nativeUrl directly
|
||||
this.url = "";
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Whether the texture is loaded or not
|
||||
* !#zh
|
||||
* 贴图是否已经成功加载
|
||||
* @property loaded
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.loaded = false;
|
||||
/**
|
||||
* !#en
|
||||
@@ -300,12 +293,6 @@ var Texture2D = cc.Class({
|
||||
update(options) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the texture's url.<br>
|
||||
* The Texture object overrides the toString() method of the Object object; it does not inherit Object.prototype.toString(). For Texture objects, the toString() method returns a string representation of the object. JavaScript calls the toString() method automatically when a texture is to be represented as a text value or when a texture is referred to in a string concatenation.
|
||||
* @method toString
|
||||
* @return {String}
|
||||
*/
|
||||
toString () {
|
||||
return this.url || '';
|
||||
},
|
||||
@@ -420,9 +407,7 @@ var Texture2D = cc.Class({
|
||||
// load image
|
||||
var self = this;
|
||||
cc.loader.load({
|
||||
url: this.url,
|
||||
// For image, we should skip loader otherwise it will load a new texture
|
||||
skips: [ 'Loader' ],
|
||||
url: this.url
|
||||
}, function (err, image) {
|
||||
if (image) {
|
||||
if (CC_DEBUG && image instanceof cc.Texture2D) {
|
||||
@@ -440,9 +425,12 @@ var Texture2D = cc.Class({
|
||||
* Check whether texture is loaded.
|
||||
* @method isLoaded
|
||||
* @returns {Boolean}
|
||||
* @deprecated use loaded property instead
|
||||
* @deprecated use `loaded` property instead
|
||||
*/
|
||||
isLoaded: function () {
|
||||
if (CC_DEBUG) {
|
||||
cc.warn('Texture2D.isLoaded is deprecated, use `loaded` property instead please.');
|
||||
}
|
||||
return this.loaded;
|
||||
},
|
||||
|
||||
@@ -1023,6 +1011,16 @@ JS.get(_p, "pixelHeight", _p.getPixelHeight);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* !#zh
|
||||
* 当该资源加载成功后触发该事件
|
||||
* !#en
|
||||
* This event is emitted when the asset is loaded
|
||||
*
|
||||
* @event load
|
||||
* @param {Event.EventCustom} event
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pixel format of the texture.
|
||||
* @property pixelFormat
|
||||
|
||||
@@ -196,7 +196,7 @@ var textureCache = /** @lends cc.textureCache# */{
|
||||
var locTexs = this._textures;
|
||||
var tex = locTexs[url];
|
||||
if (tex) {
|
||||
if(tex.isLoaded()) {
|
||||
if(tex.loaded) {
|
||||
cb && cb.call(target, tex);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -72,10 +72,10 @@ cc.path = /** @lends cc.path# */{
|
||||
* @method mainFileName
|
||||
* @param {String} fileName
|
||||
* @returns {String}
|
||||
* @deprecated
|
||||
*/
|
||||
mainFileName: function (fileName) {
|
||||
if (fileName) {
|
||||
|
||||
var idx = fileName.lastIndexOf(".");
|
||||
if (idx !== -1)
|
||||
return fileName.substring(0, idx);
|
||||
|
||||
@@ -39,7 +39,7 @@ _ccsg.MotionStreak.WebGLRenderCmd.prototype.rendering = function(ctx){
|
||||
if (node._nuPoints <= 1)
|
||||
return;
|
||||
|
||||
if (node.texture && node.texture.isLoaded()) {
|
||||
if (node.texture && node.texture.loaded) {
|
||||
ctx = ctx || cc._renderContext;
|
||||
|
||||
// update the color
|
||||
|
||||
@@ -24,15 +24,24 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const Asset = require('../core/assets/CCAsset');
|
||||
const Texture2D = require('../core/textures/CCTexture2D');
|
||||
|
||||
/**
|
||||
* Class for particle asset handling.
|
||||
* @class ParticleAsset
|
||||
* @extends RawAsset
|
||||
*
|
||||
* @extends Asset
|
||||
*/
|
||||
var ParticleAsset = cc.Class({
|
||||
name: 'cc.ParticleAsset',
|
||||
extends: cc.RawAsset,
|
||||
extends: Asset,
|
||||
|
||||
properties: {
|
||||
texture: {
|
||||
default: null,
|
||||
type: Texture2D
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cc.ParticleAsset = module.exports = ParticleAsset;
|
||||
|
||||
@@ -152,8 +152,8 @@ var properties = {
|
||||
* @default ""
|
||||
*/
|
||||
_file: {
|
||||
default: '',
|
||||
url: cc.ParticleAsset
|
||||
default: null,
|
||||
type: cc.ParticleAsset
|
||||
},
|
||||
file: {
|
||||
get: function () {
|
||||
@@ -175,7 +175,7 @@ var properties = {
|
||||
}
|
||||
},
|
||||
animatable: false,
|
||||
url: cc.ParticleAsset,
|
||||
type: cc.ParticleAsset,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.particle_system.file'
|
||||
},
|
||||
|
||||
@@ -913,7 +913,7 @@ var ParticleSystem = cc.Class({
|
||||
var file = this._file;
|
||||
if (file) {
|
||||
var self = this;
|
||||
cc.loader.load(file, function (err, content) {
|
||||
cc.loader.load(file.nativeUrl, function (err, content) {
|
||||
if (err || !content) {
|
||||
throw err || new Error(cc._getError(6029));
|
||||
}
|
||||
@@ -927,11 +927,11 @@ var ParticleSystem = cc.Class({
|
||||
var active = sgNode.isActive();
|
||||
|
||||
if (CC_EDITOR) {
|
||||
sgNode._plistFile = file;
|
||||
sgNode._plistFile = file.nativeUrl;
|
||||
sgNode.initWithDictionary(content, '');
|
||||
}
|
||||
else {
|
||||
sgNode.initWithFile(file);
|
||||
sgNode.initWithFile(file.nativeUrl);
|
||||
}
|
||||
|
||||
// To avoid it export custom particle data textureImageData too large,
|
||||
@@ -945,6 +945,9 @@ var ParticleSystem = cc.Class({
|
||||
self.texture = texture;
|
||||
});
|
||||
}
|
||||
else if (!content.textureImageData && file.texture) {
|
||||
sgNode.texture = file.texture;
|
||||
}
|
||||
|
||||
// For custom data export
|
||||
if (content.emissionRate) {
|
||||
|
||||
@@ -1158,7 +1158,6 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
|
||||
* @return {Boolean}
|
||||
*/
|
||||
initWithDictionary:function (dictionary, dirname) {
|
||||
var ret = false;
|
||||
var buffer = null;
|
||||
var image = null;
|
||||
var locValueForKey = this._valueForKey;
|
||||
@@ -1283,8 +1282,8 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
|
||||
// texture
|
||||
// Try to get the texture from the cache
|
||||
var textureName = locValueForKey("textureFileName", dictionary);
|
||||
var imgPath = cc.path.changeBasename(this._plistFile, textureName);
|
||||
var tex = cc.textureCache.getTextureForKey(imgPath);
|
||||
var imgPath = textureName && cc.path.changeBasename(this._plistFile, textureName);
|
||||
var tex = imgPath && cc.textureCache.getTextureForKey(imgPath);
|
||||
|
||||
if (tex) {
|
||||
this.setTexture(tex);
|
||||
@@ -1292,10 +1291,13 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
|
||||
var textureData = locValueForKey("textureImageData", dictionary);
|
||||
|
||||
if (!textureData || textureData.length === 0) {
|
||||
tex = cc.textureCache.addImage(imgPath);
|
||||
if (!tex)
|
||||
return false;
|
||||
this.setTexture(tex);
|
||||
if (imgPath) {
|
||||
tex = cc.textureCache.addImage(imgPath);
|
||||
if (!tex)
|
||||
return false;
|
||||
this.setTexture(tex);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
buffer = cc.Codec.unzipBase64AsArray(textureData, 1);
|
||||
if (!buffer) {
|
||||
@@ -1318,6 +1320,7 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
|
||||
tiffReader.parseTIFF(buffer,canvasObj);
|
||||
}
|
||||
|
||||
imgPath = imgPath || this._plistFile;
|
||||
cc.textureCache.cacheImage(imgPath, canvasObj);
|
||||
|
||||
var addTexture = cc.textureCache.getTextureForKey(imgPath);
|
||||
@@ -1326,9 +1329,9 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
|
||||
this.setTexture(addTexture);
|
||||
}
|
||||
}
|
||||
ret = true;
|
||||
return true;
|
||||
}
|
||||
return ret;
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -119,7 +119,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
|
||||
_fillTextureGrids: function (tileset, texId) {
|
||||
var tex = this._textures[texId];
|
||||
if (!tex.isLoaded()) {
|
||||
if (!tex.loaded) {
|
||||
tex.once('load', function () {
|
||||
this._fillTextureGrids(tileset, texId);
|
||||
}, this);
|
||||
|
||||
@@ -172,7 +172,7 @@ _ccsg.TMXObjectImage = _ccsg.Sprite.extend(/** @lends cc.TMXObjectImage# */{
|
||||
},
|
||||
|
||||
_initWithTileset: function(texture, tileset) {
|
||||
if (!texture.isLoaded()) {
|
||||
if (!texture.loaded) {
|
||||
texture.once('load', function () {
|
||||
this._initWithTileset(texture, tileset);
|
||||
}, this);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
require('../core/platform/CCSAXParser');
|
||||
require('../compression/ZipUtils');
|
||||
var Zlib = require('../compression/zlib.min');
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ var DragonBonesAsset = cc.Class({
|
||||
destroy () {
|
||||
var useGlobalFactory = !CC_JSB;
|
||||
if (useGlobalFactory && this._dragonBonesData) {
|
||||
var factory = dragonBones.CCFactory.getFactory();
|
||||
var factory = dragonBones.CCFactory.getInstance();
|
||||
factory.removeDragonBonesData(this._dragonBonesData.name, true);
|
||||
}
|
||||
this._super();
|
||||
|
||||
@@ -121,7 +121,7 @@ var DragonBonesAtlasAsset = cc.Class({
|
||||
destroy () {
|
||||
var useGlobalFactory = !CC_JSB;
|
||||
if (useGlobalFactory && this._textureAtlasData) {
|
||||
var factory = dragonBones.CCFactory.getFactory();
|
||||
var factory = dragonBones.CCFactory.getInstance();
|
||||
// If the texture still referenced by any DragonBonesData in the factory,
|
||||
// remember to remove them at the same time!
|
||||
var name = this._textureAtlasData.name;
|
||||
|
||||
@@ -147,20 +147,6 @@ sp.Skeleton = cc.Class({
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.skeleton.skeleton_data'
|
||||
},
|
||||
|
||||
///**
|
||||
// * The url of atlas file.
|
||||
// * @property {string} file
|
||||
// */
|
||||
//atlasFile: {
|
||||
// default: '',
|
||||
// url: cc.TextAsset,
|
||||
// notify: function () {
|
||||
// this.defaultSkin = '';
|
||||
// this.defaultAnimation = '';
|
||||
// this._applyAsset();
|
||||
// },
|
||||
//},
|
||||
|
||||
// 由于 spine 的 skin 是无法二次替换的,所以只能设置默认的 skin
|
||||
/**
|
||||
* !#en The name of default skin.
|
||||
|
||||
+13
-11
@@ -39,15 +39,15 @@ const Watch = require('./gulp/tasks/watch');
|
||||
// engine //
|
||||
/////////////
|
||||
|
||||
gulp.task('build-html5-dev', function (done) {
|
||||
gulp.task('build-html5-dev', ['clean-cache'], function (done) {
|
||||
Engine.buildCocosJs('./index.js', './bin/cocos2d-js.js', [], done);
|
||||
});
|
||||
|
||||
gulp.task('build-html5-min', function (done) {
|
||||
gulp.task('build-html5-min', ['clean-cache'], function (done) {
|
||||
Engine.buildCocosJsMin('./index.js', './bin/cocos2d-js-min.js', [], done);
|
||||
});
|
||||
|
||||
gulp.task('build-html5-preview', function (done) {
|
||||
gulp.task('build-html5-preview', function (done) {
|
||||
Engine.buildPreview('./index.js', './bin/cocos2d-js-for-preview.js', done);
|
||||
});
|
||||
|
||||
@@ -57,19 +57,19 @@ gulp.task('build-html5-preview-dev', function (done) {
|
||||
|
||||
gulp.task('build-html5', ['build-html5-preview', 'build-html5-dev', 'build-html5-min']);
|
||||
|
||||
gulp.task('build-jsb-dev', function (done) {
|
||||
gulp.task('build-jsb-dev', ['clean-cache'], function (done) {
|
||||
Engine.buildJsb([
|
||||
'./jsb/index.js',
|
||||
], './bin/jsb_polyfill.dev.js', [], done);
|
||||
});
|
||||
|
||||
gulp.task('build-jsb-min', function (done) {
|
||||
gulp.task('build-jsb-min', ['clean-cache'], function (done) {
|
||||
Engine.buildJsbMin([
|
||||
'./jsb/index.js',
|
||||
], './bin/jsb_polyfill.js', [], done);
|
||||
});
|
||||
|
||||
gulp.task('build-jsb-preview', function (done) {
|
||||
gulp.task('build-jsb-preview', function (done) {
|
||||
Engine.buildJsbPreview([
|
||||
'./jsb/index.js',
|
||||
], './bin/jsb_polyfill-for-preview.js', [], done);
|
||||
@@ -129,15 +129,17 @@ gulp.task('test-no-build', function (done) {
|
||||
// global //
|
||||
////////////
|
||||
|
||||
gulp.task('clean-cache', function (done) {
|
||||
Del(['./bin/.cache/*', '!./bin/.cache/dev/**'], done);
|
||||
});
|
||||
|
||||
// fast build, only for develop
|
||||
gulp.task('build-dev', ['build-html5-preview', 'build-jsb-preview'], function (done) {
|
||||
Del(['./bin/jsb_polyfill.js', './bin/jsb_polyfill.dev.js', './bin/.cache'], done);
|
||||
gulp.task('build-dev', ['clean-cache', 'build-html5-preview', 'build-jsb-preview'], function (done) {
|
||||
Del(['./bin/jsb_polyfill.js', './bin/jsb_polyfill.dev.js'], done);
|
||||
});
|
||||
|
||||
// only build preview for html5 since it will built by editor
|
||||
gulp.task('build', ['build-html5-preview', 'build-jsb'], function (done) {
|
||||
Del(['./bin/.cache'], done);
|
||||
});
|
||||
gulp.task('build', ['clean-cache', 'build-html5-preview', 'build-jsb']);
|
||||
|
||||
// default task
|
||||
gulp.task('default', ['build']);
|
||||
|
||||
+60
-68
@@ -28,32 +28,20 @@ cc.Audio = function (src) {
|
||||
this.src = src;
|
||||
this.volume = 1;
|
||||
this.loop = false;
|
||||
|
||||
this.id = -1;
|
||||
this._eventList = {};
|
||||
|
||||
this.type = cc.Audio.Type.NATIVE;
|
||||
};
|
||||
|
||||
cc.Audio.Type = {
|
||||
DOM: 'AUDIO',
|
||||
WEBAUDIO: 'WEBAUDIO',
|
||||
NATIVE: 'NATIVE',
|
||||
UNKNOWN: 'UNKNOWN'
|
||||
};
|
||||
|
||||
(function (proto, audioEngine) {
|
||||
|
||||
// Using the new audioEngine
|
||||
cc.audioEngine = audioEngine;
|
||||
audioEngine.play = audioEngine.play2d;
|
||||
audioEngine.setMaxWebAudioSize = function () {};
|
||||
|
||||
proto.State = audioEngine.AudioState;
|
||||
|
||||
proto.play = function () {
|
||||
audioEngine.stop(this.id);
|
||||
this.id = audioEngine.play2d(this.src, this.loop, this.volume);
|
||||
this.id = audioEngine.play(this.src, this.loop, this.volume);
|
||||
};
|
||||
|
||||
proto.pause = function () {
|
||||
@@ -70,20 +58,20 @@ cc.Audio.Type = {
|
||||
|
||||
proto.setLoop = function (loop) {
|
||||
this.loop = loop;
|
||||
audioEngine.setLoop(this.id, loop)
|
||||
audioEngine.setLoop(this.id, loop);
|
||||
};
|
||||
|
||||
proto.getLoop = function () {
|
||||
return audioEngine.getLoop(this.id)
|
||||
return this.loop;
|
||||
};
|
||||
|
||||
proto.setVolume = function (volume) {
|
||||
this.volume = volume;
|
||||
return audioEngine.setVolume(this.id, volume)
|
||||
return audioEngine.setVolume(this.id, volume);
|
||||
};
|
||||
|
||||
proto.getVolume = function () {
|
||||
return audioEngine.getVolume(this.id)
|
||||
return this.volume;
|
||||
};
|
||||
|
||||
proto.setCurrentTime = function (time) {
|
||||
@@ -102,62 +90,42 @@ cc.Audio.Type = {
|
||||
return audioEngine.getState(this.id)
|
||||
};
|
||||
|
||||
proto.preload = function () {
|
||||
this._loaded = true;
|
||||
this.emit('load');
|
||||
};
|
||||
|
||||
proto.on = function (event, callback) {
|
||||
var list = this._eventList[event];
|
||||
if (!list) {
|
||||
list = this._eventList[event] = [];
|
||||
}
|
||||
list.push(callback);
|
||||
};
|
||||
proto.once = function (event, callback) {
|
||||
var onceCallback = function (elem) {
|
||||
callback.call(this, elem);
|
||||
this.off(event, onceCallback);
|
||||
};
|
||||
this.on(event, onceCallback);
|
||||
};
|
||||
proto.emit = function (event) {
|
||||
var list = this._eventList[event];
|
||||
if (!list) return;
|
||||
for (var i=0; i<list.length; i++) {
|
||||
list[i].call(this, this);
|
||||
}
|
||||
};
|
||||
proto.off = function (event, callback) {
|
||||
var list = this._eventList[event];
|
||||
if (!list) return false;
|
||||
if (!callback) {
|
||||
this._eventList[event] = [];
|
||||
return true;
|
||||
}
|
||||
|
||||
for (var i=0; i<list.length; i++) {
|
||||
if (list[i] === callback) {
|
||||
list.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
// polyfill audioEngine
|
||||
|
||||
var _music = {
|
||||
id: -1,
|
||||
url: '',
|
||||
clip: '',
|
||||
loop: false,
|
||||
volume: 1
|
||||
};
|
||||
var _effect = {
|
||||
volume: 1
|
||||
};
|
||||
audioEngine.playMusic = function (filePath, loop) {
|
||||
|
||||
audioEngine.play = function (clip, loop, volume) {
|
||||
if (typeof volume !== 'number') {
|
||||
volume = 1;
|
||||
}
|
||||
var path;
|
||||
if (typeof clip === 'string') {
|
||||
// backward compatibility since 1.10
|
||||
cc.warnID(8401, 'cc.audioEngine');
|
||||
path = clip;
|
||||
}
|
||||
else {
|
||||
if (!clip) {
|
||||
return;
|
||||
}
|
||||
path = clip._nativeAsset;
|
||||
}
|
||||
path = cc.loader.md5Pipe.transformURL(path);
|
||||
return audioEngine.play2d(path, loop, volume);
|
||||
};
|
||||
audioEngine.playMusic = function (clip, loop) {
|
||||
audioEngine.stop(_music.id);
|
||||
_music.id = audioEngine.play(filePath, loop, _music.volume);
|
||||
_music.id = audioEngine.play(clip, loop, _music.volume);
|
||||
_music.loop = loop;
|
||||
_music.url = filePath;
|
||||
_music.clip = clip;
|
||||
return _music.id;
|
||||
};
|
||||
audioEngine.stopMusic = function () {
|
||||
@@ -177,7 +145,7 @@ cc.Audio.Type = {
|
||||
audioEngine.setMusicVolume = function (volume) {
|
||||
_music.volume = volume;
|
||||
audioEngine.setVolume(_music.id, _music.volume);
|
||||
return _music.volume;
|
||||
return volume;
|
||||
};
|
||||
audioEngine.isMusicPlaying = function () {
|
||||
return audioEngine.getState(_music.id) === audioEngine.AudioState.PLAYING;
|
||||
@@ -215,18 +183,42 @@ cc.Audio.Type = {
|
||||
return audioEngine.stop(id);
|
||||
};
|
||||
audioEngine.stopAllEffects = function () {
|
||||
var musicPlay = audioEngine.getState(_music.id) === audioEngine.AudioState.PLAYING;
|
||||
var musicPlaying = audioEngine.getState(_music.id) === audioEngine.AudioState.PLAYING;
|
||||
var currentTime = audioEngine.getCurrentTime(_music.id);
|
||||
audioEngine.stopAll();
|
||||
if (musicPlay) {
|
||||
_music.id = audioEngine.play(_music.url, _music.loop);
|
||||
if (musicPlaying) {
|
||||
_music.id = audioEngine.play(_music.clip, _music.loop);
|
||||
audioEngine.setCurrentTime(_music.id, currentTime);
|
||||
}
|
||||
};
|
||||
|
||||
// deprecated
|
||||
|
||||
audioEngine._uncache = audioEngine.uncache;
|
||||
audioEngine.uncache = function (clip) {
|
||||
var path;
|
||||
if (typeof clip === 'string') {
|
||||
// backward compatibility since 1.10
|
||||
cc.warnID(8401, 'cc.audioEngine');
|
||||
path = clip;
|
||||
}
|
||||
else {
|
||||
if (!clip) {
|
||||
return;
|
||||
}
|
||||
path = clip._nativeAsset;
|
||||
}
|
||||
audioEngine._uncache(path);
|
||||
};
|
||||
|
||||
audioEngine._preload = audioEngine.preload;
|
||||
audioEngine.preload = function (filePath, callback) {
|
||||
cc.warn('`cc.audioEngine.preload` is deprecated, use `cc.loader.loadRes(url, cc.AudioClip)` instead please.');
|
||||
audioEngine._preload(filePath, callback);
|
||||
};
|
||||
|
||||
var Module = require('../cocos2d/audio/deprecated');
|
||||
Module.removed(audioEngine);
|
||||
Module.deprecated(audioEngine);
|
||||
|
||||
})(cc.Audio.prototype, jsb.AudioEngine);
|
||||
})(cc.Audio.prototype, jsb.AudioEngine);
|
||||
|
||||
+16
-3
@@ -37,7 +37,18 @@ function downloadScript (item, callback) {
|
||||
}
|
||||
|
||||
function downloadAudio (item, callback) {
|
||||
return item.url;
|
||||
var loadByDeserializedAsset = item._owner instanceof cc.AudioClip;
|
||||
if (loadByDeserializedAsset) {
|
||||
return item.url;
|
||||
}
|
||||
else {
|
||||
var audioClip = new cc.AudioClip();
|
||||
// obtain user url through nativeUrl
|
||||
audioClip._setRawAsset(item.rawUrl, false);
|
||||
// obtain download url through _nativeAsset
|
||||
audioClip._nativeAsset = item.url;
|
||||
return audioClip;
|
||||
}
|
||||
}
|
||||
|
||||
cc.loader.addDownloadHandlers({
|
||||
@@ -97,7 +108,8 @@ function loadImage (item, callback) {
|
||||
else if (isRemote) {
|
||||
jsb.loadRemoteImg(url, function(succeed, tex) {
|
||||
if (succeed) {
|
||||
tex.url = url;
|
||||
tex.url = item.rawUrl;
|
||||
tex._setRawAsset(item.rawUrl, false);
|
||||
callback && callback(null, tex);
|
||||
}
|
||||
else {
|
||||
@@ -108,7 +120,8 @@ function loadImage (item, callback) {
|
||||
else {
|
||||
cc.textureCache._addImageAsync(url, function (tex) {
|
||||
if (tex instanceof cc.Texture2D) {
|
||||
tex.url = url;
|
||||
tex.url = item.rawUrl;
|
||||
tex._setRawAsset(item.rawUrl, false);
|
||||
callback && callback(null, tex);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -108,13 +108,14 @@ cc.textureCache.removeTextureForKey = function (key) {
|
||||
cc.Class._fastDefine('cc.Texture2D', cc.Texture2D, []);
|
||||
cc.Texture2D.$super = cc.Asset;
|
||||
|
||||
// polyfill static members
|
||||
[
|
||||
'WrapMode',
|
||||
'PixelFormat',
|
||||
'Filter',
|
||||
'extnames',
|
||||
'preventDeferredLoadDependents',
|
||||
'preventPreloadNativeObject',
|
||||
'preventPreloadNativeObject'
|
||||
].forEach(function (key) {
|
||||
cc.Texture2D[key] = WebTexture[key];
|
||||
});
|
||||
@@ -122,8 +123,19 @@ cc.Texture2D.$super = cc.Asset;
|
||||
prototype = cc.Texture2D.prototype;
|
||||
prototype._releaseTexture = prototype.releaseTexture;
|
||||
|
||||
// polyfill prototype
|
||||
cc.js.addon(prototype, WebTexture.prototype);
|
||||
|
||||
// polyfill inherited members
|
||||
[
|
||||
'_setRawAsset',
|
||||
'nativeUrl',
|
||||
'toString'
|
||||
].forEach(function (inheritedProp) {
|
||||
Object.defineProperty(prototype, inheritedProp, cc.js.getPropertyDescriptor(WebTexture.prototype, inheritedProp));
|
||||
});
|
||||
|
||||
|
||||
prototype._ctor = function () {
|
||||
cc.Asset.call(this);
|
||||
this.url = "";
|
||||
|
||||
+2
-1
@@ -46,7 +46,8 @@
|
||||
"name": "ParticleSystem",
|
||||
"entries": [
|
||||
"./cocos2d/particle/CCParticleSystem.js",
|
||||
"./cocos2d/particle/CCParticleAsset.js"
|
||||
"./cocos2d/particle/CCParticleAsset.js",
|
||||
"./cocos2d/core/platform/CCSAXParser.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"__type__": "cc.AudioClip",
|
||||
"_native": ".mp3",
|
||||
"loadMode": 0
|
||||
}
|
||||
@@ -1,34 +1,35 @@
|
||||
if (!isPhantomJS) {
|
||||
largeModule('AudioScource');
|
||||
var libPath = assetDir + '/library';
|
||||
largeModule('AudioScource', {
|
||||
setup: function () {
|
||||
_resetGame();
|
||||
AssetLibrary.init({libraryPath: libPath});
|
||||
}
|
||||
});
|
||||
|
||||
var AUDIO_UUID = '1258a1';
|
||||
|
||||
asyncTest('basic test', function () {
|
||||
var node = new cc.Node();
|
||||
cc.director.getScene().addChild(node);
|
||||
AssetLibrary.loadAsset(AUDIO_UUID, function (err, clip) {
|
||||
var node = new cc.Node();
|
||||
cc.director.getScene().addChild(node);
|
||||
|
||||
var audioSource = node.addComponent(cc.AudioSource);
|
||||
var audioSource = node.addComponent(cc.AudioSource);
|
||||
audioSource.clip = clip;
|
||||
|
||||
audioSource.clip = assetDir + "/background.mp3";
|
||||
audioSource.play();
|
||||
strictEqual(audioSource.isPlaying, true, 'audio scource play state true after play');
|
||||
|
||||
audioSource.play();
|
||||
audioSource.volume = 0.5;
|
||||
strictEqual(audioSource.audio._volume, 0.5, 'audio scource volume after play');
|
||||
|
||||
audioSource.loop = true;
|
||||
strictEqual(audioSource.audio._loop, true, 'audio scource loop after play');
|
||||
|
||||
audioSource.mute = true;
|
||||
strictEqual(audioSource.audio._volume, 0, 'audio scource volume after mute');
|
||||
|
||||
audioSource.audio.on('load', function () {
|
||||
clearTimeout(timerId);
|
||||
strictEqual(audioSource.isPlaying, true, 'audio scource play state true after preload');
|
||||
start();
|
||||
});
|
||||
|
||||
var timerId = setTimeout(function () {
|
||||
ok(false, 'time out!');
|
||||
start();
|
||||
}, 10000);
|
||||
|
||||
//audioSource.volume = 0.5;
|
||||
//strictEqual(audioSource.audio.volume, 0.5, 'audio scource volume true');
|
||||
|
||||
//audioSource.loop = true;
|
||||
//strictEqual(audioSource.audio.loop, true, 'audio scource loop true');
|
||||
|
||||
//audioSource.mute = true;
|
||||
//strictEqual(audioSource.audio.volume, 0, 'audio scource mute true');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ asyncTest('Load with dependencies', function () {
|
||||
type: 'deps'
|
||||
};
|
||||
var json2 = assetDir + '/library/deferred-loading/74/748321.json';
|
||||
var audio = assetDir + '/background.mp3';
|
||||
var audio = assetDir + '/library/12/1258a1.json';
|
||||
var resources = [
|
||||
json1,
|
||||
json2,
|
||||
@@ -112,7 +112,7 @@ asyncTest('Load with dependencies', function () {
|
||||
}
|
||||
else if (item.id === audio) {
|
||||
// Test environment doesn't support audio
|
||||
ok((item.content instanceof cc.Audio) || true, 'audio url\'s result should be Audio');
|
||||
ok((item.content instanceof cc.AudioClip) || true, 'audio url\'s result should be AudioClip');
|
||||
}
|
||||
else if (item.id === dep1 || item.id === dep2 || item.id === dep3) {
|
||||
depsProgression();
|
||||
|
||||
Reference in New Issue
Block a user