Skip to content

Commit

Permalink
Merge pull request cocos#1135 from pandamicro/loader
Browse files Browse the repository at this point in the history
Refactor CCLoader to support multi queues and better progression
  • Loading branch information
nantas authored Sep 26, 2016
2 parents 97b87ec + 90b63e4 commit 788778b
Show file tree
Hide file tree
Showing 17 changed files with 567 additions and 510 deletions.
48 changes: 9 additions & 39 deletions cocos2d/audio/CCAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
THE SOFTWARE.
****************************************************************************/

var EventTarget = require('../core/event/event-target');

var touchBinded = false;
var touchPlayList = [
//{ offset: 0, audio: audio }
];

var Audio = function (src) {
EventTarget.call(this);

this.src = src;
this._audioType = Audio.Type.UNKNOWN;
this._element = null;
Expand All @@ -39,6 +43,8 @@ var Audio = function (src) {
this._loaded = false;
};

cc.js.extend(Audio, EventTarget);

Audio.Type = {
DOM: 'AUDIO',
WEBAUDIO: 'WEBAUDIO',
Expand Down Expand Up @@ -70,46 +76,10 @@ Audio.State = {
}
});
}
audio.mount(item.element || item.buffer);
audio.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;
}
else if (item.complete) {
audio.mount(item.element || item.buffer);
audio.emit('load');
}
return true;
};

proto.mount = function (elem) {
Expand Down
3 changes: 2 additions & 1 deletion cocos2d/core/CCDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,8 @@ cc.DisplayLinkDirector = cc.Director.extend(/** @lends cc.Director# */{
},

/**
* Sets animation interval
* Sets animation interval, this doesn't control the main loop.
* To control the game's frame rate overall, please use {{#crossLink "Game.setFrameRate"}}cc.game.setFrameRate{{/crossLink}}
* @param {Number} value - The animation interval desired.
*/
setAnimationInterval: function (value) {
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/components/CCAudioSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var AudioSource = cc.Class({

onDestroy: function () {
this.stop();
audioEngine.uncache(this._clip);
cc.audioEngine.uncache(this._clip);
},

/**
Expand Down
Loading

0 comments on commit 788778b

Please sign in to comment.