Skip to content

Commit 967682f

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 abf1a2f commit 967682f

File tree

11 files changed

+53
-40
lines changed

11 files changed

+53
-40
lines changed

cocos2d/actions/CCActionGrid3D.js

+1-1
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
/**

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/layers_scenes_transitions_nodes/CCLayer.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -793,15 +793,9 @@ cc.LayerColor = cc.LayerRGBA.extend(/** @lends cc.LayerColor# */{
793793
_squareVerticesAB:null,
794794
_squareColorsAB:null,
795795

796-
/**
797-
* Constructor
798-
*/
799-
ctor: null,
800-
801796
_ctorForCanvas: function () {
802797
cc.LayerRGBA.prototype.ctor.call(this);
803798
this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST);
804-
this._color = new cc.Color4B(0, 0, 0, 0);
805799
},
806800

807801
_ctorForWebGL: function () {
@@ -1045,7 +1039,6 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
10451039
ctor:function () {
10461040
cc.LayerColor.prototype.ctor.call(this);
10471041

1048-
this._color = new cc.Color3B(0, 0, 0);
10491042
this._startColor = new cc.Color3B(0, 0, 0);
10501043
this._endColor = new cc.Color3B(0, 0, 0);
10511044
this._alongVector = cc.p(0, -1);
@@ -1060,7 +1053,7 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
10601053
* @return {cc.Color3B}
10611054
*/
10621055
getStartColor:function () {
1063-
return this._color;
1056+
return this._realColor;
10641057
},
10651058

10661059
/**
@@ -1135,15 +1128,16 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
11351128
* @param {cc.Point} Var
11361129
*/
11371130
setVector:function (Var) {
1138-
this._alongVector = Var;
1131+
this._alongVector.x = Var.x;
1132+
this._alongVector.y = Var.y;
11391133
this._updateColor();
11401134
},
11411135

11421136
/**
11431137
* @return {cc.Point}
11441138
*/
11451139
getVector:function () {
1146-
return this._alongVector;
1140+
return cc.p(this._alongVector.x, this._alongVector.y);
11471141
},
11481142

11491143
/** 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

+2-2
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
/**
@@ -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/CCSpriteFrame.js

+17-7
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

@@ -130,7 +134,10 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{
130134
* @param {cc.Rect} rect
131135
*/
132136
setRect:function (rect) {
133-
this._rect = rect;
137+
this._rect.x = rect.x;
138+
this._rect.y = rect.y;
139+
this._rect.width = rect.width;
140+
this._rect.height = rect.height;
134141
this._rectInPixels = cc.RECT_POINTS_TO_PIXELS(this._rect);
135142
},
136143

@@ -147,7 +154,8 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{
147154
* @param {cc.Point} offsetInPixels
148155
*/
149156
setOffsetInPixels:function (offsetInPixels) {
150-
this._offsetInPixels = offsetInPixels;
157+
this._offsetInPixels.x = offsetInPixels.x;
158+
this._offsetInPixels.y = offsetInPixels.y;
151159
this._offset = cc.POINT_PIXELS_TO_POINTS(this._offsetInPixels);
152160
},
153161

@@ -157,15 +165,16 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{
157165
* @return {cc.Size}
158166
*/
159167
getOriginalSizeInPixels:function () {
160-
return this._originalSizeInPixels;
168+
return cc.size(this._originalSizeInPixels.width, this._originalSizeInPixels.height);
161169
},
162170

163171
/**
164172
* set original size of the trimmed image
165173
* @param {cc.Size} sizeInPixels
166174
*/
167175
setOriginalSizeInPixels:function (sizeInPixels) {
168-
this._originalSizeInPixels = sizeInPixels;
176+
this._originalSizeInPixels.width = sizeInPixels.width;
177+
this._originalSizeInPixels.height = sizeInPixels.height;
169178
},
170179

171180
/**
@@ -182,7 +191,8 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{
182191
* @param {cc.Size} sizeInPixels
183192
*/
184193
setOriginalSize:function (sizeInPixels) {
185-
this._originalSize = sizeInPixels;
194+
this._originalSize.width = sizeInPixels.width;
195+
this._originalSize.height = sizeInPixels.height;
186196
},
187197

188198
/**

cocos2d/tileMap_parallax_nodes/CCTMXLayer.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -186,29 +186,31 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{
186186
* @return {cc.Size}
187187
*/
188188
getLayerSize:function () {
189-
return this._layerSize;
189+
return cc.size(this._layerSize.width, this._layerSize.height);
190190
},
191191

192192
/**
193193
* @param {cc.Size} Var
194194
*/
195195
setLayerSize:function (Var) {
196-
this._layerSize = Var;
196+
this._layerSize.width = Var.width;
197+
this._layerSize.height = Var.height;
197198
},
198199

199200
/**
200201
* Size of the map's tile (could be different from the tile's size)
201202
* @return {cc.Size}
202203
*/
203204
getMapTileSize:function () {
204-
return this._mapTileSize;
205+
return cc.size(this._mapTileSize.width,this._mapTileSize.height);
205206
},
206207

207208
/**
208209
* @param {cc.Size} Var
209210
*/
210211
setMapTileSize:function (Var) {
211-
this._mapTileSize = Var;
212+
this._mapTileSize.width = Var.width;
213+
this._mapTileSize.height = Var.height;
212214
},
213215

214216
/**

cocos2d/tileMap_parallax_nodes/CCTMXObjectGroup.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ cc.TMXObjectGroup = cc.Class.extend(/** @lends cc.TMXObjectGroup# */{
5151
* @return {cc.Point}
5252
*/
5353
getPositionOffset:function () {
54-
return this._positionOffset;
54+
return cc.p(this._positionOffset.x,this._positionOffset.y);
5555
},
5656

5757
/**
5858
* @param {cc.Point} Var
5959
*/
6060
setPositionOffset:function (Var) {
61-
this._positionOffset = Var;
61+
this._positionOffset.x = Var.x;
62+
this._positionOffset.y = Var.y;
6263
},
6364

6465
/**

cocos2d/tileMap_parallax_nodes/CCTMXTiledMap.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,30 @@ cc.TMXTiledMap = cc.Node.extend(/** @lends cc.TMXTiledMap# */{
126126
* @return {cc.Size}
127127
*/
128128
getMapSize:function () {
129-
return this._mapSize;
129+
return cc.size(this._mapSize.width, this._mapSize.height);
130130
},
131131

132132
/**
133133
* @param {cc.Size} Var
134134
*/
135135
setMapSize:function (Var) {
136-
this._mapSize = Var;
136+
this._mapSize.width = Var.width;
137+
this._mapSize.height = Var.height;
137138
},
138139

139140
/**
140141
* @return {cc.Size}
141142
*/
142143
getTileSize:function () {
143-
return this._tileSize;
144+
return cc.size(this._tileSize.width, this._tileSize.height);
144145
},
145146

146147
/**
147148
* @param {cc.Size} Var
148149
*/
149150
setTileSize:function (Var) {
150-
this._tileSize = Var;
151+
this._tileSize.width = Var.width;
152+
this._tileSize.height = Var.height;
151153
},
152154

153155
/**

cocos2d/tileMap_parallax_nodes/CCTMXXMLParser.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -296,29 +296,31 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
296296
* @return {cc.Size}
297297
*/
298298
getMapSize:function () {
299-
return this._mapSize;
299+
return cc.size(this._mapSize.width,this._mapSize.height);
300300
},
301301

302302
/**
303303
* @param {cc.Size} Var
304304
*/
305305
setMapSize:function (Var) {
306-
this._mapSize = Var;
306+
this._mapSize.width = Var.width;
307+
this._mapSize.height = Var.height;
307308
},
308309

309310
/**
310311
* Tiles width & height
311312
* @return {cc.Size}
312313
*/
313314
getTileSize:function () {
314-
return this._tileSize;
315+
return cc.size(this._tileSize.width, this._tileSize.height);
315316
},
316317

317318
/**
318319
* @param {cc.Size} Var
319320
*/
320321
setTileSize:function (Var) {
321-
this._tileSize = Var;
322+
this._tileSize.width = Var.width;
323+
this._tileSize.height = Var.height;
322324
},
323325

324326
/**

0 commit comments

Comments
 (0)