Skip to content

Commit f8789ea

Browse files
committed
Merge pull request #1158 from dingpinglv/Iss2833_ReturnNewObjectForFunciton
Closed #2833: Returning a new object instead returning an object's reference for some Engine class to avoid some mistake.
2 parents bca328b + d965487 commit f8789ea

File tree

14 files changed

+85
-62
lines changed

14 files changed

+85
-62
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ cc.Lens3D = cc.Grid3DAction.extend(/** @lends cc.Lens3D# */{
366366
* @return {cc.Point}
367367
*/
368368
getPosition:function () {
369-
return this._position;
369+
return cc.p(this._position.x,this._position.y);
370370
},
371371

372372
/**
@@ -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/effects/CCGrid.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ cc.GridBase = cc.Class.extend(/** @lends cc.GridBase# */{
9797
* @return {cc.Size}
9898
*/
9999
getGridSize:function () {
100-
return this._gridSize;
100+
return cc.size(this._gridSize.width, this._gridSize.height);
101101
},
102102

103103
/**
@@ -114,15 +114,16 @@ cc.GridBase = cc.Class.extend(/** @lends cc.GridBase# */{
114114
* @return {cc.Point}
115115
*/
116116
getStep:function () {
117-
return this._step;
117+
return cc.p(this._step.x, this._step.y);
118118
},
119119

120120
/**
121121
* set pixels between the grids
122122
* @param {cc.Point} step
123123
*/
124124
setStep:function (step) {
125-
this._step = step;
125+
this._step.x = step.x;
126+
this._step.y = step.y;
126127
},
127128

128129
/**

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

+21-20
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
},
@@ -786,15 +793,9 @@ cc.LayerColor = cc.LayerRGBA.extend(/** @lends cc.LayerColor# */{
786793
_squareVerticesAB:null,
787794
_squareColorsAB:null,
788795

789-
/**
790-
* Constructor
791-
*/
792-
ctor: null,
793-
794796
_ctorForCanvas: function () {
795797
cc.LayerRGBA.prototype.ctor.call(this);
796798
this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST);
797-
this._color = new cc.Color4B(0, 0, 0, 0);
798799
},
799800

800801
_ctorForWebGL: function () {
@@ -1038,7 +1039,6 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
10381039
ctor:function () {
10391040
cc.LayerColor.prototype.ctor.call(this);
10401041

1041-
this._color = new cc.Color3B(0, 0, 0);
10421042
this._startColor = new cc.Color3B(0, 0, 0);
10431043
this._endColor = new cc.Color3B(0, 0, 0);
10441044
this._alongVector = cc.p(0, -1);
@@ -1053,7 +1053,7 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
10531053
* @return {cc.Color3B}
10541054
*/
10551055
getStartColor:function () {
1056-
return this._color;
1056+
return this._realColor;
10571057
},
10581058

10591059
/**
@@ -1128,15 +1128,16 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
11281128
* @param {cc.Point} Var
11291129
*/
11301130
setVector:function (Var) {
1131-
this._alongVector = Var;
1131+
this._alongVector.x = Var.x;
1132+
this._alongVector.y = Var.y;
11321133
this._updateColor();
11331134
},
11341135

11351136
/**
11361137
* @return {cc.Point}
11371138
*/
11381139
getVector:function () {
1139-
return this._alongVector;
1140+
return cc.p(this._alongVector.x, this._alongVector.y);
11401141
},
11411142

11421143
/** is Compressed Interpolation

cocos2d/misc_nodes/CCProgressTimer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ cc.ProgressTimer = cc.NodeRGBA.extend(/** @lends cc.ProgressTimer# */{
7777
* @return {cc.Point}
7878
*/
7979
getMidpoint:function () {
80-
return this._midPoint;
80+
return cc.p(this._midPoint.x, this._midPoint);
8181
},
8282

8383
/**
@@ -96,7 +96,7 @@ cc.ProgressTimer = cc.NodeRGBA.extend(/** @lends cc.ProgressTimer# */{
9696
* @return {cc.Point}
9797
*/
9898
getBarChangeRate:function () {
99-
return this._barChangeRate;
99+
return cc.p(this._barChangeRate.x, this._barChangeRate.y);
100100
},
101101

102102
/**

cocos2d/particle_nodes/CCParticleSystem.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
727727
*/
728728
getGravity:function () {
729729
cc.Assert(this._emitterMode == cc.PARTICLE_MODE_GRAVITY, "Particle Mode should be Gravity");
730-
return this.modeA.gravity;
730+
var locGravity = this.modeA.gravity;
731+
return cc.p(locGravity.x, locGravity.y);
731732
},
732733

733734
/**

cocos2d/platform/CCEGLView.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{
227227
* @return {cc.Size}
228228
*/
229229
getFrameSize:function () {
230-
return this._screenSize;
230+
return cc.size(this._screenSize.width, this._screenSize.height);
231231
},
232232

233233
/**
@@ -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

@@ -363,7 +363,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{
363363
* @return {cc.Size}
364364
*/
365365
getDesignResolutionSize:function () {
366-
return this._designResolutionSize;
366+
return cc.size(this._designResolutionSize.width, this._designResolutionSize.height);
367367
},
368368

369369
/**

cocos2d/sprite_nodes/CCSprite.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,13 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{
521521
* Do not call it manually. Use setTextureRect instead. <br/>
522522
* (override this method to generate "double scale" sprites)
523523
* </p>
524-
* @param rect
524+
* @param {cc.Rect} rect
525525
*/
526526
setVertexRect:function (rect) {
527-
this._rect = rect;
527+
this._rect.x = rect.x;
528+
this._rect.y = rect.y;
529+
this._rect.width = rect.width;
530+
this._rect.height = rect.height;
528531
},
529532

530533
sortAllChildren:function () {

cocos2d/sprite_nodes/CCSpriteFrame.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,18 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{
8888
* @return {cc.Rect}
8989
*/
9090
getRectInPixels:function () {
91-
return this._rectInPixels;
91+
var locRectInPixels = this._rectInPixels;
92+
return cc.rect(locRectInPixels.x, locRectInPixels.y, locRectInPixels.width, locRectInPixels.height);
9293
},
9394

9495
/**
9596
* @param {cc.Rect} rectInPixels
9697
*/
9798
setRectInPixels:function (rectInPixels) {
98-
this._rectInPixels = rectInPixels;
99+
this._rectInPixels.x = rectInPixels.x;
100+
this._rectInPixels.y = rectInPixels.y;
101+
this._rectInPixels.width = rectInPixels.width;
102+
this._rectInPixels.height = rectInPixels.height;
99103
this._rect = cc.RECT_PIXELS_TO_POINTS(rectInPixels);
100104
},
101105

@@ -122,15 +126,19 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{
122126
* @return {cc.Rect}
123127
*/
124128
getRect:function () {
125-
return this._rect;
129+
var locRect = this._rect;
130+
return cc.rect(locRect.x, locRect.y, locRect.width, locRect.height);
126131
},
127132

128133
/**
129134
* set rect of the frame
130135
* @param {cc.Rect} rect
131136
*/
132137
setRect:function (rect) {
133-
this._rect = rect;
138+
this._rect.x = rect.x;
139+
this._rect.y = rect.y;
140+
this._rect.width = rect.width;
141+
this._rect.height = rect.height;
134142
this._rectInPixels = cc.RECT_POINTS_TO_PIXELS(this._rect);
135143
},
136144

@@ -147,7 +155,8 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{
147155
* @param {cc.Point} offsetInPixels
148156
*/
149157
setOffsetInPixels:function (offsetInPixels) {
150-
this._offsetInPixels = offsetInPixels;
158+
this._offsetInPixels.x = offsetInPixels.x;
159+
this._offsetInPixels.y = offsetInPixels.y;
151160
this._offset = cc.POINT_PIXELS_TO_POINTS(this._offsetInPixels);
152161
},
153162

@@ -157,15 +166,16 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{
157166
* @return {cc.Size}
158167
*/
159168
getOriginalSizeInPixels:function () {
160-
return this._originalSizeInPixels;
169+
return cc.size(this._originalSizeInPixels.width, this._originalSizeInPixels.height);
161170
},
162171

163172
/**
164173
* set original size of the trimmed image
165174
* @param {cc.Size} sizeInPixels
166175
*/
167176
setOriginalSizeInPixels:function (sizeInPixels) {
168-
this._originalSizeInPixels = sizeInPixels;
177+
this._originalSizeInPixels.width = sizeInPixels.width;
178+
this._originalSizeInPixels.height = sizeInPixels.height;
169179
},
170180

171181
/**
@@ -182,7 +192,8 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{
182192
* @param {cc.Size} sizeInPixels
183193
*/
184194
setOriginalSize:function (sizeInPixels) {
185-
this._originalSize = sizeInPixels;
195+
this._originalSize.width = sizeInPixels.width;
196+
this._originalSize.height = sizeInPixels.height;
186197
},
187198

188199
/**

0 commit comments

Comments
 (0)