Skip to content

Commit b523263

Browse files
author
linshun
committed
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-html5 into iss2264_v2.1.4
2 parents 0fb6283 + af88c1a commit b523263

File tree

6 files changed

+106
-103
lines changed

6 files changed

+106
-103
lines changed

CocosDenshion/SimpleAudioEngine.js

Lines changed: 76 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ var cc = cc || {};
3333
* @extends cc.Class
3434
*/
3535
cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
36-
36+
_audioID:0,
37+
_audioIDList:null,
38+
ctor:function(){
39+
this._audioIDList = {};
40+
},
3741
/**
3842
* Check each type to see if it can be played by current browser
3943
* @param {Object} capabilities The results are filled into this dict
@@ -129,8 +133,9 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
129133
* Constructor
130134
*/
131135
ctor:function () {
132-
this._supportedFormat = [];
136+
cc.AudioEngine.prototype.ctor.call(this);
133137

138+
this._supportedFormat = [];
134139
this._checkCanPlay(this._capabilities);
135140

136141
// enable sound if any of the audio format is supported
@@ -399,8 +404,10 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
399404
au.loop = loop;
400405
}
401406
au.play();
407+
var audioID = this._audioID++;
408+
this._audioIDList[audioID] = au;
402409

403-
return path;
410+
return audioID;
404411
},
405412

406413
/**
@@ -446,21 +453,18 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
446453

447454
/**
448455
* Pause playing sound effect.
449-
* @param {String} path The return value of function playEffect.
456+
* @param {Number} audioID The return value of function playEffect.
450457
* @example
451458
* //example
452-
* cc.AudioEngine.getInstance().pauseEffect(path);
459+
* cc.AudioEngine.getInstance().pauseEffect(audioID);
453460
*/
454-
pauseEffect:function (path) {
455-
if (!path) return;
456-
var keyname = this._getPathWithoutExt(path);
457-
if (this._effectList.hasOwnProperty(keyname)) {
458-
var tmpArr = this._effectList[keyname], au;
459-
for (var i = tmpArr.length - 1; i >= 0; i--) {
460-
au = tmpArr[i];
461-
if (!au.ended) {
462-
au.pause();
463-
}
461+
pauseEffect:function (audioID) {
462+
if (audioID == null) return;
463+
464+
if (this._audioIDList.hasOwnProperty(audioID)) {
465+
var au = this._audioIDList[audioID];
466+
if (!au.ended) {
467+
au.pause();
464468
}
465469
}
466470
},
@@ -486,24 +490,18 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
486490

487491
/**
488492
* Resume playing sound effect.
489-
* @param {String} path The return value of function playEffect.
490-
* @example
493+
* @param {Number} audioID The return value of function playEffect.
494+
* @audioID
491495
* //example
492-
* cc.AudioEngine.getInstance().resumeEffect(path);
496+
* cc.AudioEngine.getInstance().resumeEffect(audioID);
493497
*/
494-
resumeEffect:function (path) {
495-
if (!path) return;
496-
var tmpArr, au;
497-
var keyname = this._getPathWithoutExt(path);
498-
if (this._effectList.hasOwnProperty(keyname)) {
499-
tmpArr = this._effectList[keyname];
500-
if (tmpArr.length > 0) {
501-
for (var i = 0; i < tmpArr.length; i++) {
502-
au = tmpArr[i];
503-
if (!au.ended) {
504-
au.play();
505-
}
506-
}
498+
resumeEffect:function (audioID) {
499+
if (audioID == null) return;
500+
501+
if (this._audioIDList.hasOwnProperty(audioID)) {
502+
var au = this._audioIDList[audioID];
503+
if (!au.ended) {
504+
au.play();
507505
}
508506
}
509507
},
@@ -531,25 +529,19 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
531529

532530
/**
533531
* Stop playing sound effect.
534-
* @param {String} path The return value of function playEffect.
532+
* @param {Number} audioID The return value of function playEffect.
535533
* @example
536534
* //example
537-
* cc.AudioEngine.getInstance().stopEffect(path);
535+
* cc.AudioEngine.getInstance().stopEffect(audioID);
538536
*/
539-
stopEffect:function (path) {
540-
if (!path) return;
541-
var tmpArr, au;
542-
var keyname = this._getPathWithoutExt(path);
543-
if (this._effectList.hasOwnProperty(keyname)) {
544-
tmpArr = this._effectList[keyname];
545-
if (tmpArr.length > 0) {
546-
for (var i = 0; i < tmpArr.length; i++) {
547-
au = tmpArr[i];
548-
if (!au.ended) {
549-
au.loop = false;
550-
au.currentTime = au.duration;
551-
}
552-
}
537+
stopEffect:function (audioID) {
538+
if (audioID == null) return;
539+
540+
if (this._audioIDList.hasOwnProperty(audioID)) {
541+
var au = this._audioIDList[audioID];
542+
if (!au.ended) {
543+
au.loop = false;
544+
au.currentTime = au.duration;
553545
}
554546
}
555547
},
@@ -588,6 +580,15 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
588580
this.stopEffect(path);
589581
delete this._effectList[keyname];
590582
}
583+
584+
var au,pathName;
585+
for (var k in this._audioIDList) {
586+
au = this._audioIDList[k];
587+
pathName = this._getPathWithoutExt(au.src);
588+
if(pathName == keyname){
589+
delete this._audioIDList[k];
590+
}
591+
}
591592
},
592593

593594
_getEffectList:function (elt) {
@@ -701,7 +702,9 @@ cc.WebAudioEngine = cc.AudioEngine.extend(/** @lends cc.WebAudioEngine# */{
701702
/**
702703
* Constructor
703704
*/
704-
ctor: function() {},
705+
ctor: function() {
706+
cc.AudioEngine.prototype.ctor.call(this);
707+
},
705708

706709
/**
707710
* Initialization
@@ -1165,8 +1168,12 @@ cc.WebAudioEngine = cc.AudioEngine.extend(/** @lends cc.WebAudioEngine# */{
11651168
*/
11661169
});
11671170
}
1171+
11681172
// cc.SimpleAudioEngine returns path, just do the same for backward compatibility. DO NOT rely on this, though!
1169-
return path;
1173+
var audioID = this._audioID++;
1174+
this._audioIDList[audioID] = this._effects[keyName];
1175+
1176+
return audioID;
11701177
},
11711178

11721179
/**
@@ -1223,23 +1230,19 @@ cc.WebAudioEngine = cc.AudioEngine.extend(/** @lends cc.WebAudioEngine# */{
12231230

12241231
/**
12251232
* Pause playing sound effect.
1226-
* @param {String} path The return value of function playEffect.
1233+
* @param {Number} audioID The return value of function playEffect.
12271234
* @example
12281235
* //example
1229-
* cc.AudioEngine.getInstance().pauseEffect(path);
1236+
* cc.AudioEngine.getInstance().pauseEffect(audioID);
12301237
*/
1231-
pauseEffect: function(path) {
1232-
if (!path) {
1238+
pauseEffect: function(audioID) {
1239+
if (audioID == null) {
12331240
return;
12341241
}
12351242

1236-
var keyName = this._getPathWithoutExt(path);
1237-
if (!(keyName in this._effects)) {
1238-
// the effect is not even in the playing list
1239-
return;
1243+
if (this._audioIDList.hasOwnProperty(audioID)) {
1244+
this._pauseSoundList(this._audioIDList[audioID]);
12401245
}
1241-
1242-
this._pauseSoundList(this._effects[keyName]);
12431246
},
12441247

12451248
/**
@@ -1270,23 +1273,19 @@ cc.WebAudioEngine = cc.AudioEngine.extend(/** @lends cc.WebAudioEngine# */{
12701273

12711274
/**
12721275
* Resume playing sound effect.
1273-
* @param {String} path The return value of function playEffect.
1276+
* @param {Number} audioID The return value of function playEffect.
12741277
* @example
12751278
* //example
1276-
* cc.AudioEngine.getInstance().resumeEffect(path);
1279+
* cc.AudioEngine.getInstance().resumeEffect(audioID);
12771280
*/
1278-
resumeEffect: function(path) {
1279-
if (!path) {
1281+
resumeEffect: function(audioID) {
1282+
if (audioID == null) {
12801283
return;
12811284
}
12821285

1283-
var keyName = this._getPathWithoutExt(path);
1284-
if (!(keyName in this._effects)) {
1285-
// the effect is not even in the playing list
1286-
return;
1286+
if (this._audioIDList.hasOwnProperty(audioID)) {
1287+
this._resumeSoundList(this._audioIDList[audioID], this.getEffectsVolume());
12871288
}
1288-
1289-
this._resumeSoundList(this._effects[keyName], this.getEffectsVolume());
12901289
},
12911290

12921291
/**
@@ -1303,27 +1302,19 @@ cc.WebAudioEngine = cc.AudioEngine.extend(/** @lends cc.WebAudioEngine# */{
13031302

13041303
/**
13051304
* Stop playing sound effect.
1306-
* @param {String} path The return value of function playEffect.
1305+
* @param {Number} audioID The return value of function playEffect.
13071306
* @example
13081307
* //example
1309-
* cc.AudioEngine.getInstance().stopEffect(path);
1308+
* cc.AudioEngine.getInstance().stopEffect(audioID);
13101309
*/
1311-
stopEffect: function(path) {
1312-
if (!path) {
1310+
stopEffect: function(audioID) {
1311+
if (audioID == null) {
13131312
return;
13141313
}
13151314

1316-
var keyName = this._getPathWithoutExt(path);
1317-
if (!(keyName in this._effects)) {
1318-
// can stop only when it's playing/paused, in other words, when it's on the list
1319-
return;
1320-
}
1321-
1322-
var effectList = this._effects[keyName];
1323-
for (var idx in effectList) {
1324-
this._endSound(effectList[idx]);
1315+
if (this._audioIDList.hasOwnProperty(audioID)) {
1316+
this._endSound(this._audioIDList[audioID]);
13251317
}
1326-
delete this._effects[keyName];
13271318
},
13281319

13291320
/**
@@ -1383,7 +1374,8 @@ cc.AudioEngine.isMusicPlaying = false;
13831374
*/
13841375
cc.AudioEngine.getInstance = function () {
13851376
if (!this._instance) {
1386-
if (cc.Browser.supportWebAudio) {
1377+
var ua = navigator.userAgent;
1378+
if (cc.Browser.supportWebAudio && (/iPhone OS/.test(ua)||/iPad/.test(ua))) {
13871379
this._instance = new cc.WebAudioEngine();
13881380
} else {
13891381
this._instance = new cc.SimpleAudioEngine();

cocos2d/label_nodes/CCLabelTTF.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,13 @@ cc.LabelTTFWebGL = cc.Sprite.extend(/** @lends cc.LabelTTFWebGL# */{
757757
_updateTexture:function () {
758758
this._labelContext = this._getLabelContext();
759759

760+
if(this._string.length === 0){
761+
this._labelCanvas.width = 1;
762+
this._labelCanvas.height = this._contentSize.height;
763+
this.setTextureRect(cc.rect(0, 0, 1, this._contentSize.height));
764+
return true;
765+
}
766+
760767
//set size for labelCanvas
761768
this._labelContext.font = this._fontStyleStr;
762769
this._updateTTF();
@@ -774,7 +781,7 @@ cc.LabelTTFWebGL = cc.Sprite.extend(/** @lends cc.LabelTTFWebGL# */{
774781

775782
_needUpdateTexture:false,
776783
visit:function(){
777-
if(this._needUpdateTexture && this._string.length > 0){
784+
if(this._needUpdateTexture ){
778785
this._needUpdateTexture = false;
779786
this._updateTexture();
780787
}

cocos2d/particle_nodes/CCParticleSystem.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,6 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
14041404
this.setTexture(canvasObj);
14051405
else
14061406
this.setTexture(addTexture);
1407-
14081407
}
14091408
}
14101409

@@ -1480,8 +1479,13 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
14801479
addParticle:function () {
14811480
if (this.isFull())
14821481
return false;
1483-
1484-
var particle =this._particles[this._particleCount];
1482+
var particle, particles = this._particles;
1483+
if(cc.renderContextType === cc.CANVAS && this._particleCount < particles.length){
1484+
particle =particles[this._particleCount];
1485+
}else{
1486+
particle = new cc.Particle();
1487+
particles.push(particle);
1488+
}
14851489
this.initParticle(particle);
14861490
++this._particleCount;
14871491
return true;

cocos2d/platform/miniFramework.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ cc.Browser = {};
8484

8585
// check if browser supports Web Audio
8686
cc.Browser.supportWebAudio = (function(){
87-
// check <audio> tag first
88-
var ele = document.createElement('audio');
89-
if (!ele) {
90-
return false;
91-
}
92-
9387
// check Web Audio's context
9488
try {
9589
var ctx = new (window.AudioContext || window.webkitAudioContext || window.mozAudioContext)();

cocos2d/sprite_nodes/CCSprite.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,6 @@ cc.SpriteWebGL = cc.Node.extend(/** @lends cc.SpriteWebGL# */{
21142114
this._quad.tl.colors = new cc.Color4B(255, 255, 255, 255);
21152115
this._quad.tr.colors = new cc.Color4B(255, 255, 255, 255);
21162116
this._quadDirty = true;
2117-
this.setShaderProgram(cc.ShaderCache.getInstance().programForKey(cc.SHADER_POSITION_TEXTURECOLOR));
21182117

21192118
// updated in "useSelfRender"
21202119
// Atlas: TexCoords
@@ -2517,6 +2516,11 @@ cc.SpriteWebGL = cc.Node.extend(/** @lends cc.SpriteWebGL# */{
25172516
// If batchnode, then texture id should be the same
25182517
cc.Assert(!this._batchNode, "cc.Sprite: Batched sprites should use the same texture as the batchnode");
25192518

2519+
if(texture)
2520+
this.setShaderProgram(cc.ShaderCache.getInstance().programForKey(cc.SHADER_POSITION_TEXTURECOLOR));
2521+
else
2522+
this.setShaderProgram(cc.ShaderCache.getInstance().programForKey(cc.SHADER_POSITION_COLOR));
2523+
25202524
if (!this._batchNode && this._texture != texture) {
25212525
this._texture = texture;
25222526
this._updateBlendFunc();
@@ -2647,9 +2651,8 @@ cc.SpriteWebGL = cc.Node.extend(/** @lends cc.SpriteWebGL# */{
26472651
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
26482652
}
26492653
} else {
2650-
var shaderProgram = cc.ShaderCache.getInstance().programForKey(cc.SHADER_POSITION_COLOR);
2651-
shaderProgram.use();
2652-
shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
2654+
this._shaderProgram.use();
2655+
this._shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
26532656

26542657
cc.glBlendFunc(this._blendFunc.src, this._blendFunc.dst);
26552658
cc.glBindTexture2D(null);

0 commit comments

Comments
 (0)