Skip to content

Commit abf1a2f

Browse files
committed
Issue #2833: Returning a new object instead returning an object's reference for some Engine class to avoid some mistake.
1 parent a8eca2f commit abf1a2f

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

cocos2d/CCDirector.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
435435
* @return {cc.Size}
436436
*/
437437
getWinSize:function () {
438-
return this._winSizeInPoints;
438+
return cc.size(this._winSizeInPoints.width, this._winSizeInPoints.height);
439439
},
440440

441441
/**
@@ -453,17 +453,15 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
453453
getVisibleSize:function () {
454454
if (this._openGLView) {
455455
return this._openGLView.getVisibleSize();
456-
}
457-
else {
456+
} else {
458457
return cc.size(0,0);
459458
}
460459
},
461460

462461
getVisibleOrigin:function () {
463462
if (this._openGLView) {
464463
return this._openGLView.getVisibleOrigin();
465-
}
466-
else {
464+
} else {
467465
return cc.p(0, 0);
468466
}
469467
},
@@ -939,6 +937,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
939937

940938
/**
941939
* seconds per frame
940+
* @return {Number}
942941
*/
943942
getSecondsPerFrame:function () {
944943
return this._secondsPerFrame;

cocos2d/actions/CCActionGrid3D.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ cc.Ripple3D = cc.Grid3DAction.extend(/** @lends cc.Ripple3D# */{
487487
* @return {cc.Point}
488488
*/
489489
getPosition:function () {
490-
return this._position;
490+
return cc.p(this._position.x, this._position.y);
491491
},
492492

493493
/**
@@ -899,7 +899,7 @@ cc.Twirl = cc.Grid3DAction.extend({
899899
* @return {cc.Point}
900900
*/
901901
getPosition:function () {
902-
return this._position;
902+
return cc.p(this._position.x, this._position.y);
903903
},
904904

905905
/**

cocos2d/label_nodes/CCLabelTTF.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
172172
* @return {cc.Size}
173173
*/
174174
getDimensions:function () {
175-
return this._dimensions;
175+
return cc.size(this._dimensions.width, this._dimensions.height);
176176
},
177177

178178
/**

cocos2d/layers_scenes_transitions_nodes/CCLayer.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ cc.LayerRGBA = cc.Layer.extend(/** @lends cc.LayerRGBA# */{
635635
* @param {Number} parentOpacity
636636
*/
637637
updateDisplayedOpacity: function (parentOpacity) {
638-
this._displayedOpacity = this._realOpacity * parentOpacity/255.0;
638+
this._displayedOpacity = 0|(this._realOpacity * parentOpacity/255.0);
639639

640640
if (this._cascadeOpacityEnabled){
641641
var locChildren = this._children;
@@ -656,37 +656,44 @@ cc.LayerRGBA = cc.Layer.extend(/** @lends cc.LayerRGBA# */{
656656
},
657657

658658
getColor: function () {
659-
return this._realColor;
659+
var locRealColor = this._realColor;
660+
return cc.c3b(locRealColor.r, locRealColor.g, locRealColor.b);
660661
},
661662

662663
getDisplayedColor: function () {
663-
return this._displayedColor;
664+
var locDisplayedColor = this._displayedColor;
665+
return cc.c3b(locDisplayedColor.r, locDisplayedColor.g, locDisplayedColor.b);
664666
},
665667

666668
setColor: function (color) {
667-
this._displayedColor = cc.c3b(color.r, color.g, color.b);
668-
this._realColor = cc.c3b(color.r,color.g, color.b);
669+
var locDisplayed = this._displayedColor, locRealColor = this._realColor;
670+
locDisplayed.r = locRealColor.r = color.r;
671+
locDisplayed.g = locRealColor.g = color.g;
672+
locDisplayed.b = locRealColor.b = color.b;
669673

670674
if (this._cascadeColorEnabled){
671-
var parentColor = cc.white();
675+
var parentColor;
672676
var locParent = this._parent;
673677
if (locParent && locParent.RGBAProtocol && locParent.isCascadeColorEnabled())
674678
parentColor = locParent.getDisplayedColor();
679+
else
680+
parentColor = cc.white();
675681
this.updateDisplayedColor(parentColor);
676682
}
677683
},
678684

679685
updateDisplayedColor: function (parentColor) {
680-
this._displayedColor.r = this._realColor.r * parentColor.r/255.0;
681-
this._displayedColor.g = this._realColor.g * parentColor.g/255.0;
682-
this._displayedColor.b = this._realColor.b * parentColor.b/255.0;
686+
var locDisplayedColor = this._displayedColor, locRealColor = this._realColor;
687+
locDisplayedColor.r = 0|(locRealColor.r * parentColor.r/255.0);
688+
locDisplayedColor.g = 0|(locRealColor.g * parentColor.g/255.0);
689+
locDisplayedColor.b = 0|(locRealColor.b * parentColor.b/255.0);
683690

684691
if (this._cascadeColorEnabled){
685692
var locChildren = this._children;
686693
for(var i = 0; i < locChildren.length; i++){
687694
var selItem = locChildren[i];
688695
if(selItem && selItem.RGBAProtocol)
689-
selItem.updateDisplayedColor(this._displayedColor);
696+
selItem.updateDisplayedColor(locDisplayedColor);
690697
}
691698
}
692699
},

cocos2d/platform/CCEGLView.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{
257257
if (this._resolutionPolicy === cc.RESOLUTION_POLICY.NOBORDER) {
258258
return cc.size(this._screenSize.width / this._scaleX, this._screenSize.height / this._scaleY);
259259
} else {
260-
return this._designResolutionSize;
260+
return cc.size(this._designResolutionSize.width, this._designResolutionSize.height);
261261
}
262262
},
263263

0 commit comments

Comments
 (0)