Skip to content

Commit 4262b1d

Browse files
committed
Merge pull request #1 from cocos2d/develop
Pull down updates from cocos2d:develop
2 parents 24991e2 + c1522ab commit 4262b1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2208
-369
lines changed

CocosDenshion/SimpleAudioEngine.js

+486-16
Large diffs are not rendered by default.

HelloHTML5World/main.js

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var cocos2dApp = cc.Application.extend({
4343
// initialize director
4444
var director = cc.Director.getInstance();
4545

46-
cc.EGLView.getInstance()._adjustSizeToBrowser();
4746
cc.EGLView.getInstance()._resizeWithBrowserSize(true);
4847
cc.EGLView.getInstance().setDesignResolutionSize(800, 450, cc.RESOLUTION_POLICY.SHOW_ALL);
4948

README.mdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Contact us
3232
------------------
3333
* Forum: [http://forum.cocos2d-x.org][5]
3434
* Twitter: [http://www.twitter.com/cocos2dhtml5][6]
35-
* Sina macro-blog: [http://t.sina.com.cn/cocos2dhtml5][7]
35+
* Sina Microblog: [http://t.sina.com.cn/cocos2dhtml5][7]
3636

3737
[1]: http://www.cocos2d-x.org "Cocos2d-html5"
3838
[2]: http://www.cocos2d-x.org "Cocos2d-X"

cocos2d/CCScheduler.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,9 @@ cc.Scheduler = cc.Class.extend(/** @lends cc.Scheduler# */{
450450
/**
451451
* find Object from Array
452452
* @private
453-
* @param {Array} Source Array
454-
* @param {cc.Class} destination object
455-
* @return {cc.ListEntry} object if finded, or return null
453+
* @param {Array} array Array
454+
* @param {cc.Class} target object
455+
* @return {cc.ListEntry} object if found, or return null
456456
*/
457457
_findElementFromArray:function (array, target) {
458458
for (var i = 0; i < array.length; i++) {

cocos2d/actions/CCActionInterval.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ cc.Sequence = cc.ActionInterval.extend(/** @lends cc.Sequence# */{
229229
var locSplit = this._split, locActions = this._actions, locLast = this._last;
230230
if (time < locSplit) {
231231
// action[0]
232-
new_t = (locSplit) ? time / locSplit : 1;
232+
new_t = (locSplit !== 0) ? time / locSplit : 1;
233233

234234
if (found === 0 && locLast === 1) {
235235
// Reverse mode ?

cocos2d/label_nodes/CCLabelBMFont.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{
583583
updateDisplayedOpacity:function(parentOpacity){
584584
this._displayedOpacity = this._realOpacity * parentOpacity/255.0;
585585
var locChildren = this._children;
586-
for(var i = 0; i< locChildren; i++){
586+
for(var i = 0; i< locChildren.length; i++){
587587
var locChild = locChildren[i];
588588
if(cc.Browser.supportWebGL){
589589
locChild.updateDisplayedOpacity(this._displayedOpacity);

cocos2d/label_nodes/CCLabelTTF.js

+49-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
3939
_fontName: null,
4040
_fontSize:0.0,
4141
_string:"",
42+
_originalText: null,
4243
_isMultiLine:false,
4344
_fontStyleStr:null,
4445

@@ -496,14 +497,37 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
496497
*/
497498
setString:function (text) {
498499
text = String(text);
499-
if (this._string != text) {
500-
this._string = text + "";
500+
if (this._originalText != text) {
501+
this._originalText = text + "";
502+
503+
this._updateString();
501504

502505
// Force update
503506
this._needUpdateTexture = true;
504507
}
505508
},
509+
_updateString: function() {
510+
if (this._originalText.length > 1) {
511+
if (this._dimensions.width > 0 && this._dimensions.height > 0) {
512+
var buffer = [];
513+
var maxWidth = 0;
514+
for (var i = 0; i < this._originalText.length ; i ++) {
515+
var width = cc.LabelTTF._getCharWidth(this._originalText.charCodeAt(i), this._fontSize, this._fontName);
516+
517+
if (maxWidth + width > this._dimensions.width) {
518+
buffer.push('\n');
519+
maxWidth = 0;
520+
}
506521

522+
buffer.push(this._originalText[i]);
523+
maxWidth += width;
524+
}
525+
this._string = buffer.join("");
526+
return;
527+
}
528+
}
529+
this._string = this._originalText;
530+
},
507531
/**
508532
* set Horizontal Alignment of cc.LabelTTF
509533
* @param {cc.TEXT_ALIGNMENT_LEFT|cc.TEXT_ALIGNMENT_CENTER|cc.TEXT_ALIGNMENT_RIGHT} alignment Horizontal Alignment
@@ -537,7 +561,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
537561
setDimensions:function (dim) {
538562
if (dim.width != this._dimensions.width || dim.height != this._dimensions.height) {
539563
this._dimensions = dim;
540-
564+
this._updateString();
541565
// Force udpate
542566
this._needUpdateTexture = true;
543567
}
@@ -1008,6 +1032,28 @@ if(cc.USE_LA88_LABELS)
10081032
else
10091033
cc.LabelTTF._SHADER_PROGRAM = cc.SHADER_POSITION_TEXTUREA8COLOR;
10101034

1035+
cc.LabelTTF.__charWidthCache = {};
1036+
cc.LabelTTF._getCharWidth = function(code, fontSize, fontName) {
1037+
if (!cc.LabelTTF.__charWidthCache[fontName + fontSize]) {
1038+
var label = cc.LabelTTF.create("字", fontName, fontSize);
1039+
var width = label.getContentSize().width;
1040+
var label2 = cc.LabelTTF.create("a", fontName, fontSize);
1041+
var width2 = label2.getContentSize().width;
1042+
cc.LabelTTF.__charWidthCache[fontName + fontSize] = {
1043+
double: width,
1044+
single: width2
1045+
};
1046+
}
1047+
1048+
var _charCache = cc.LabelTTF.__charWidthCache[fontName + fontSize];
1049+
var isDouble = code > 255;
1050+
if (isDouble) {
1051+
return _charCache.double;
1052+
}
1053+
else {
1054+
return _charCache.single;
1055+
}
1056+
};
10111057
cc.LabelTTF.__labelHeightDiv = document.createElement("div");
10121058
cc.LabelTTF.__labelHeightDiv.style.fontFamily = "Arial";
10131059
cc.LabelTTF.__labelHeightDiv.style.position = "absolute";

cocos2d/misc_nodes/CCProgressTimer.js

+2
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ cc.ProgressTimer = cc.NodeRGBA.extend(/** @lends cc.ProgressTimer# */{
633633
return;
634634
}
635635
}
636+
this._updateColor();
636637

637638
var locVertexData = this._vertexData;
638639
if (!sameIndexCount) {
@@ -770,6 +771,7 @@ cc.ProgressTimer = cc.NodeRGBA.extend(/** @lends cc.ProgressTimer# */{
770771
locVertexData[5].texCoords = this._textureCoordFromAlphaPoint(cc.p(max.x, min.y));
771772
locVertexData[5].vertices = this._vertexFromAlphaPoint(cc.p(max.x, min.y));
772773
}
774+
this._updateColor();
773775
},
774776

775777
_updateColor:function () {

cocos2d/platform/CCApplication.js

+50-29
Original file line numberDiff line numberDiff line change
@@ -167,62 +167,65 @@ cc.isAddedHiddenEvent = false;
167167
*/
168168
cc.setup = function (el, width, height) {
169169
var element = cc.$(el) || cc.$('#' + el);
170+
var localCanvas, localContainer, localConStyle;
170171
if (element.tagName == "CANVAS") {
171172
width = width || element.width;
172173
height = height || element.height;
173174

174175
//it is already a canvas, we wrap it around with a div
175-
cc.container = cc.$new("DIV");
176-
cc.canvas = element;
177-
cc.canvas.parentNode.insertBefore(cc.container, cc.canvas);
178-
cc.canvas.appendTo(cc.container);
179-
cc.container.style.width = (width || 480) + "px";
180-
cc.container.style.height = (height || 320) + "px";
181-
cc.container.setAttribute('id', 'Cocos2dGameContainer');
182-
cc.container.style.margin = "0 auto";
183-
cc.canvas.setAttribute("width", width || 480);
184-
cc.canvas.setAttribute("height", height || 320);
176+
localContainer = cc.container = cc.$new("DIV");
177+
localConStyle = localContainer.style;
178+
localCanvas = cc.canvas = element;
179+
localCanvas.parentNode.insertBefore(localContainer, localCanvas);
180+
localCanvas.appendTo(localContainer);
181+
localConStyle.width = (width || 480) + "px";
182+
localConStyle.height = (height || 320) + "px";
183+
localContainer.setAttribute('id', 'Cocos2dGameContainer');
184+
localConStyle.margin = "0 auto";
185+
localCanvas.setAttribute("width", width || 480);
186+
localCanvas.setAttribute("height", height || 320);
185187
} else {//we must make a new canvas and place into this element
186188
if (element.tagName != "DIV") {
187189
cc.log("Warning: target element is not a DIV or CANVAS");
188190
}
189191
width = width || element.clientWidth;
190192
height = height || element.clientHeight;
191193

192-
cc.canvas = cc.$new("CANVAS");
193-
cc.canvas.addClass("gameCanvas");
194-
cc.canvas.setAttribute("width", width || 480);
195-
cc.canvas.setAttribute("height", height || 320);
196-
cc.container = element;
197-
element.appendChild(cc.canvas);
198-
cc.container.style.width = (width || 480) + "px";
199-
cc.container.style.height = (height || 320) + "px";
200-
cc.container.style.margin = "0 auto";
194+
localCanvas = cc.canvas = cc.$new("CANVAS");
195+
localCanvas.addClass("gameCanvas");
196+
localCanvas.setAttribute("width", width || 480);
197+
localCanvas.setAttribute("height", height || 320);
198+
localContainer = cc.container = element;
199+
localConStyle = localContainer.style;
200+
element.appendChild(localCanvas);
201+
localConStyle.width = (width || 480) + "px";
202+
localConStyle.height = (height || 320) + "px";
203+
localConStyle.margin = "0 auto";
201204
}
202-
cc.container.style.position = 'relative';
203-
cc.container.style.overflow = 'hidden';
204-
cc.container.top = '100%';
205+
localConStyle.position = 'relative';
206+
localConStyle.overflow = 'hidden';
207+
localContainer.top = '100%';
205208

206209
if(cc.__renderDoesnotSupport)
207210
return;
208211

209212
if (cc.Browser.supportWebGL)
210-
cc.renderContext = cc.webglContext = cc.create3DContext(cc.canvas,{'stencil': true, 'preserveDrawingBuffer': true, 'alpha': false });
213+
cc.renderContext = cc.webglContext = cc.create3DContext(localCanvas,{'stencil': true, 'preserveDrawingBuffer': true, 'alpha': false });
211214
if(cc.renderContext){
212215
cc.renderContextType = cc.WEBGL;
213216
window.gl = cc.renderContext; // global variable declared in CCMacro.js
214217
cc.drawingUtil = new cc.DrawingPrimitiveWebGL(cc.renderContext);
215218
cc.TextureCache.getInstance()._initializingRenderer();
216219
} else {
217-
cc.renderContext = cc.canvas.getContext("2d");
220+
cc.renderContext = localCanvas.getContext("2d");
218221
cc.mainRenderContextBackup = cc.renderContext;
219222
cc.renderContextType = cc.CANVAS;
220-
cc.renderContext.translate(0, cc.canvas.height);
223+
cc.renderContext.translate(0, localCanvas.height);
221224
cc.drawingUtil = new cc.DrawingPrimitiveCanvas(cc.renderContext);
222225
}
223226

224-
cc.originalCanvasSize = cc.size(cc.canvas.width, cc.canvas.height);
225-
cc.gameDiv = cc.container;
227+
cc.originalCanvasSize = cc.size(localCanvas.width, localCanvas.height);
228+
cc.gameDiv = localContainer;
226229

227230
cc.log(cc.ENGINE_VERSION);
228231
cc.Configuration.getInstance();
@@ -250,13 +253,30 @@ cc.setup = function (el, width, height) {
250253
}
251254

252255
function handleVisibilityChange() {
253-
if (!document[hidden])
256+
var audioEngine = cc.AudioEngine.getInstance();
257+
if (!document[hidden]){
254258
cc.Director.getInstance()._resetLastUpdate();
259+
audioEngine.resumeAllEffects();
260+
audioEngine.resumeMusic();
261+
} else{
262+
audioEngine.pauseAllEffects();
263+
audioEngine.pauseMusic();
264+
}
255265
}
256266

257267
if (typeof document.addEventListener === "undefined" ||
258268
typeof hidden === "undefined") {
259269
cc.isAddedHiddenEvent = false;
270+
window.addEventListener("focus", function () {
271+
var audioEngine = cc.AudioEngine.getInstance();
272+
audioEngine.resumeAllEffects();
273+
audioEngine.resumeMusic();
274+
}, false);
275+
window.addEventListener("blur", function () {
276+
var audioEngine = cc.AudioEngine.getInstance();
277+
audioEngine.pauseAllEffects();
278+
audioEngine.pauseMusic();
279+
}, false);
260280
} else {
261281
cc.isAddedHiddenEvent = true;
262282
document.addEventListener(visibilityChange, handleVisibilityChange, false);
@@ -275,7 +295,8 @@ cc._addUserSelectStatus = function(){
275295
cc._addBottomTag = function () {
276296
var bottom = document.createElement("div");
277297
bottom.id = "bottom";
278-
bottom.style.border = bottom.style.margin = bottom.style.padding = bottom.style.height = bottom.style.lineHeight = bottom.style.fontSize = "0px";
298+
var bStyle = bottom.style;
299+
bStyle.border = bStyle.margin = bStyle.padding = bStyle.height = bStyle.lineHeight = bStyle.fontSize = "0px";
279300
document.body.appendChild(bottom);
280301
window.location.href="#bottom";
281302
};

cocos2d/platform/CCClass.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ ClassManager.getNewInstanceId=function(){
151151

152152
// The dummy Class constructor
153153
function Class() {
154+
this.__instanceId = ClassManager.getNewInstanceId();
154155
// All construction is actually done in the init method
155156
if (this.ctor)
156157
this.ctor.apply(this, arguments);
157-
this.__instanceId = ClassManager.getNewInstanceId();
158158
}
159159

160160
Class.id = classId;

cocos2d/platform/CCCommon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ cc._logToWebPage = function (message) {
100100
logList = document.createElement("ul");
101101
logDiv.appendChild(logList);
102102
logList.setAttribute("id", "logInfoList");
103-
logList.style.height = "200px";
103+
logList.style.height = cc.canvas.height + "px";
104104
logList.style.color = "#fff";
105105
logList.style.textAlign = "left";
106106
logList.style.listStyle = "disc outside";
@@ -142,7 +142,7 @@ cc._logToWebPage = function (message) {
142142
*/
143143
cc.log = function (message) {
144144
if (!cc.IS_SHOW_DEBUG_ON_PAGE) {
145-
console.log(message);
145+
console.log.apply(console, arguments);
146146
} else {
147147
cc._logToWebPage(message);
148148
}

cocos2d/sprite_nodes/CCSprite.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ cc.generateTintImage = function (texture, tintedImgCache, color, rect, renderCan
207207
ctx.drawImage(tintedImgCache[2], rect.x, rect.y, w, h, 0, 0, w, h);
208208
}
209209

210-
if ((selColor.r === 0) && (selColor.g === 0) && (selColor.b === 0)) {
210+
if (selColor.r + selColor.g + selColor.b < 255) {
211211
ctx.globalAlpha = a;
212212
ctx.drawImage(tintedImgCache[3], rect.x, rect.y, w, h, 0, 0, w, h);
213213
}

extensions/CocoStudio/Action/CCActionFrame.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
THE SOFTWARE.
2323
****************************************************************************/
2424

25-
25+
/**
26+
* Action frame type
27+
* @constant
28+
* @type Object
29+
*/
2630
ccs.FrameType = {
2731
move: 0,
2832
scale: 1,
@@ -35,9 +39,9 @@ ccs.FrameType = {
3539
/**
3640
* Base class for ccs.ActionFrame
3741
* @class
38-
* @extends cc.Class
42+
* @extends ccs.Class
3943
*/
40-
ccs.ActionFrame = cc.Class.extend({
44+
ccs.ActionFrame = ccs.Class.extend(/** @lends ccs.ActionFrame# */{
4145
_frameType: 0,
4246
_easingType: 0,
4347
_frameIndex: 0,

extensions/CocoStudio/Action/CCActionManager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
/**
2626
* Base class for ccs.ActionManager
2727
* @class
28-
* @extends cc.Class
28+
* @extends ccs.Class
2929
*/
30-
ccs.ActionManager = cc.Class.extend({
30+
ccs.ActionManager = ccs.Class.extend(/** @lends ccs.ActionManager# */{
3131
_actionDic: null,
3232
ctor: function () {
3333
this._actionDic = {};

extensions/CocoStudio/Action/CCActionNode.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
/**
2626
* Base class for ccs.ActionNode
2727
* @class
28-
* @extends cc.Class
28+
* @extends ccs.Class
2929
*/
30-
ccs.ActionNode = cc.Class.extend({
30+
ccs.ActionNode = ccs.Class.extend({
3131
_currentFrameIndex: 0,
3232
_destFrameIndex: 0,
3333
_unitTime: 0,

extensions/CocoStudio/Action/CCActionObject.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
/**
2626
* Base class for ccs.ActionObject
2727
* @class
28-
* @extends cc.Class
28+
* @extends ccs.Class
2929
*/
30-
ccs.ActionObject = cc.Class.extend({
30+
ccs.ActionObject = ccs.Class.extend({
3131
_actionNodeList: null,
3232
_name: "",
3333
_loop: false,

extensions/CocoStudio/Armature/CCArmature.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
/**
2626
* Base class for ccs.Armature objects.
2727
* @class
28-
* @extends cc.NodeRGBA
28+
* @extends ccs.NodeRGBA
2929
*/
30-
ccs.Armature = cc.NodeRGBA.extend({
30+
ccs.Armature = ccs.NodeRGBA.extend(/** @lends ccs.Armature# */{
3131
_animation:null,
3232
_armatureData:null,
3333
_batchNode:null,

0 commit comments

Comments
 (0)