Skip to content

Commit 27623dd

Browse files
More JS API fixes:
replaces SizeMake() with size() replaces RectMake() with rect() The constant colors are not functions, but constants: cc.WHITE() -> cc.WHITE cc.BLACK() -> cc.BLACK. etc.
1 parent 4ae079c commit 27623dd

Some content is hidden

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

42 files changed

+179
-198
lines changed

HelloHTML5World/src/myApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var CircleSprite = cc.Sprite.extend({
3939
},
4040
myUpdate:function (dt) {
4141
this._radians -= 6;
42-
//this._addDirtyRegionToDirector(this.boundingBoxToWorld());
42+
//this._addDirtyRegionToDirector(this.getBoundingBoxToWorld());
4343
}
4444
});
4545

cocos2d/CCDirector.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
230230

231231
//purge?
232232
this._purgeDirecotorInNextLoop = false;
233-
this._winSizeInPixels = this._winSizeInPoints = cc.SizeMake(cc.canvas.width, cc.canvas.height);
233+
this._winSizeInPixels = this._winSizeInPoints = cc.size(cc.canvas.width, cc.canvas.height);
234234

235235
this._openGLView = null;
236236
this._contentScaleFactor = 1.0;
@@ -657,7 +657,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
657657
reshapeProjection:function (newWindowSize) {
658658
if(this._openGLView){
659659
this._winSizeInPoints = this._openGLView.getSize();
660-
this._winSizeInPixels = cc.SizeMake(this._winSizeInPoints.width * this._contentScaleFactor,
660+
this._winSizeInPixels = cc.size(this._winSizeInPoints.width * this._contentScaleFactor,
661661
this._winSizeInPoints.height * this._contentScaleFactor);
662662

663663
this.setProjection(this._projection);
@@ -728,7 +728,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
728728
setContentScaleFactor:function (scaleFactor) {
729729
if (scaleFactor != this._contentScaleFactor) {
730730
this._contentScaleFactor = scaleFactor;
731-
this._winSizeInPixels = cc.SizeMake(this._winSizeInPoints.width * scaleFactor, this._winSizeInPoints.height * scaleFactor);
731+
this._winSizeInPixels = cc.size(this._winSizeInPoints.width * scaleFactor, this._winSizeInPoints.height * scaleFactor);
732732

733733
if (this._openGLView) {
734734
this.updateContentScaleFactor();
@@ -834,7 +834,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
834834

835835
// set size
836836
this._winSizeInPoints = this._openGLView.getSize();
837-
this._winSizeInPixels = cc.SizeMake(this._winSizeInPoints.width * this._contentScaleFactor, this._winSizeInPoints.height * this._contentScaleFactor);
837+
this._winSizeInPixels = cc.size(this._winSizeInPoints.width * this._contentScaleFactor, this._winSizeInPoints.height * this._contentScaleFactor);
838838

839839
this._createStatsLabel();
840840

@@ -1132,9 +1132,9 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
11321132
},
11331133

11341134
_createStatsLabel:function(){
1135-
this._FPSLabel = cc.LabelTTF.create("00.0", "Arial", 18, cc.SizeMake(60,16), cc.TEXT_ALIGNMENT_RIGHT);
1136-
this._SPFLabel = cc.LabelTTF.create("0.000", "Arial", 18, cc.SizeMake(60,16), cc.TEXT_ALIGNMENT_RIGHT);
1137-
this._drawsLabel = cc.LabelTTF.create("000", "Arial", 18, cc.SizeMake(60,16), cc.TEXT_ALIGNMENT_RIGHT);
1135+
this._FPSLabel = cc.LabelTTF.create("00.0", "Arial", 18, cc.size(60,16), cc.TEXT_ALIGNMENT_RIGHT);
1136+
this._SPFLabel = cc.LabelTTF.create("0.000", "Arial", 18, cc.size(60,16), cc.TEXT_ALIGNMENT_RIGHT);
1137+
this._drawsLabel = cc.LabelTTF.create("000", "Arial", 18, cc.size(60,16), cc.TEXT_ALIGNMENT_RIGHT);
11381138

11391139
this._drawsLabel.setPosition( cc.pAdd( cc.p(20,48), cc.DIRECTOR_STATS_POSITION ) );
11401140
this._SPFLabel.setPosition( cc.pAdd( cc.p(20,30), cc.DIRECTOR_STATS_POSITION ) );

cocos2d/actions/CCAction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ cc.Follow = cc.Action.extend(/** @lends cc.Follow# */{
468468
* // example
469469
* // creates the action with a set boundary
470470
* var sprite = cc.Sprite.create("spriteFileName");
471-
* var followAction = cc.Follow.create(sprite, cc.RectMake(0, 0, s.width * 2 - 100, s.height));
471+
* var followAction = cc.Follow.create(sprite, cc.rect(0, 0, s.width * 2 - 100, s.height));
472472
* this.runAction(followAction);
473473
*
474474
* // creates the action with no boundary set

cocos2d/actions/CCActionGrid3D.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ cc.Twirl = cc.Grid3DAction.extend({
778778
var amp = 0.1 * this._amplitude * this._amplitudeRate;
779779
var a = r * Math.cos(Math.PI / 2.0 + time * Math.PI * this._twirls * 2) * amp;
780780

781-
var d = cc.p();
781+
var d = cc.p(0,0);
782782

783783
d.x = Math.sin(a) * (v.y - c.y) + Math.cos(a) * (v.x - c.x);
784784
d.y = Math.cos(a) * (v.y - c.y) - Math.sin(a) * (v.x - c.x);

cocos2d/actions/CCActionInterval.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ cc.BezierBy = cc.ActionInterval.extend(/** @lends cc.BezierBy# */{
12411241
*/
12421242
ctor:function () {
12431243
this._config = new cc.BezierConfig();
1244-
this._startPosition = cc.p();
1244+
this._startPosition = cc.p(0,0);
12451245
}
12461246
});
12471247

cocos2d/base_nodes/CCAtlasNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{
7171
this._itemHeight = tileHeight;
7272

7373
this._opacity = 255;
74-
this._color = this._colorUnmodified = cc.WHITE();
74+
this._color = this._colorUnmodified = cc.WHITE;
7575
this._isOpacityModifyRGB = true;
7676

7777
this._blendFunc.src = cc.BLEND_SRC;

cocos2d/base_nodes/CCNode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,15 +871,15 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
871871
* @return {Number}
872872
*/
873873
getBoundingBox:function () {
874-
var rect = cc.RectMake(0, 0, this._contentSize.width, this._contentSize.height);
874+
var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height);
875875
return cc.RectApplyAffineTransform(rect, this.nodeToParentTransform());
876876
},
877877

878878
/**
879879
* @return {cc.Rect}
880880
*/
881881
getBoundingBoxToWorld:function () {
882-
var rect = cc.RectMake(0, 0, this._contentSize.width, this._contentSize.height);
882+
var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height);
883883
rect = cc.RectApplyAffineTransform(rect, this.nodeToWorldTransform());
884884
rect = new cc.Rect(0 | rect.origin.x - 4, 0 | rect.origin.y - 4, 0 | rect.size.width + 8, 0 | rect.size.height + 8);
885885
//query child's BoundingBox

cocos2d/base_nodes/CCdomNode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ cc.DOM.methods = {
5151
},
5252
setScale:function (scale, scaleY) {
5353
//save dirty region when before change
54-
//this._addDirtyRegionToDirector(this.boundingBoxToWorld());
54+
//this._addDirtyRegionToDirector(this.getBoundingBoxToWorld());
5555

5656
this._scaleX = scale;
5757
this._scaleY = scaleY || scale;
5858

5959
//save dirty region when after changed
60-
//this._addDirtyRegionToDirector(this.boundingBoxToWorld());
60+
//this._addDirtyRegionToDirector(this.getBoundingBoxToWorld());
6161
this.dom.resize(this._scaleX, this._scaleY);
6262
},
6363
setScaleX:function (x) {
@@ -99,7 +99,7 @@ cc.DOM.methods = {
9999
if (this._rotation == newRotation)
100100
return;
101101
//save dirty region when before change
102-
//this._addDirtyRegionToDirector(this.boundingBoxToWorld());
102+
//this._addDirtyRegionToDirector(this.getBoundingBoxToWorld());
103103

104104
this._rotation = newRotation;
105105
this._rotationRadians = this._rotation * (Math.PI / 180);

cocos2d/cocoa/CCAffineTransform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ cc.AffineTransformMake = function (a, b, c, d, tx, ty) {
6262
};
6363

6464
cc.__PointApplyAffineTransform = function (point, t) {
65-
var p = cc.p();
65+
var p = cc.p(0,0);
6666
p.x = t.a * point.x + t.c * point.y + t.tx;
6767
p.y = t.b * point.x + t.d * point.y + t.ty;
6868
return p;
@@ -138,7 +138,7 @@ cc.RectApplyAffineTransform = function (rect, anAffineTransform) {
138138
var minY = Math.min(Math.min(topLeft.y, topRight.y), Math.min(bottomLeft.y, bottomRight.y));
139139
var maxY = Math.max(Math.max(topLeft.y, topRight.y), Math.max(bottomLeft.y, bottomRight.y));
140140

141-
return cc.RectMake(minX, minY, (maxX - minX), (maxY - minY));
141+
return cc.rect(minX, minY, (maxX - minX), (maxY - minY));
142142
};
143143

144144
/**

cocos2d/cocoa/CCGeometry.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ cc.Point = function (_x, _y) {
3535
this.y = _y || 0;
3636
};
3737

38+
/**
39+
* Helper macro that creates a cc.Point.
40+
* @param {Number} x
41+
* @param {Number} y
42+
* @return {}
43+
*/
44+
cc.p = function (x, y) {
45+
return new cc.Point(x,y);
46+
};
47+
3848
/**
3949
* @function
4050
* @param {cc.Point} point1
@@ -81,29 +91,29 @@ cc.Rect = function (x1, y1, width1, height1) {
8191
switch (arguments.length) {
8292
case 0:
8393
this.origin = cc.p(0, 0);
84-
this.size = new cc.Size(0, 0);
94+
this.size = cc.size(0, 0);
8595
break;
8696
case 1:
8797
var oldRect = x1;
8898
if (!oldRect) {
8999
this.origin = cc.p(0, 0);
90-
this.size = new cc.Size(0, 0);
100+
this.size = cc.size(0, 0);
91101
} else {
92102
if (oldRect instanceof cc.Rect) {
93103
this.origin = cc.p(oldRect.origin.x, oldRect.origin.y);
94-
this.size = new cc.Size(oldRect.size.width, oldRect.size.height);
104+
this.size = cc.size(oldRect.size.width, oldRect.size.height);
95105
} else {
96106
throw "unknown argument type";
97107
}
98108
}
99109
break;
100110
case 2:
101111
this.origin = x1 ? cc.p(x1.x, x1.y) : cc.p(0, 0);
102-
this.size = y1 ? new cc.Size(y1.width, y1.height) : new cc.Size(0, 0);
112+
this.size = y1 ? cc.size(y1.width, y1.height) : cc.size(0, 0);
103113
break;
104114
case 4:
105115
this.origin = cc.p(x1 || 0, y1 || 0);
106-
this.size = new cc.Size(width1 || 0, height1 || 0);
116+
this.size = cc.size(width1 || 0, height1 || 0);
107117
break;
108118
default:
109119
throw "unknown argument type";
@@ -250,7 +260,7 @@ cc.Rect.CCRectOverlapsRect = function (rectA, rectB) {
250260
* Constructor
251261
*/
252262
cc.Rect.CCRectUnion = function (rectA, rectB) {
253-
var rect = new cc.Rect(0, 0, 0, 0);
263+
var rect = cc.rect(0, 0, 0, 0);
254264
rect.origin.x = Math.min(rectA.origin.x, rectB.origin.x);
255265
rect.origin.y = Math.min(rectA.origin.y, rectB.origin.y);
256266
rect.size.width = Math.max(rectA.origin.x + rectA.size.width, rectB.origin.x + rectB.size.width) - rect.origin.x;
@@ -267,7 +277,7 @@ cc.Rect.CCRectUnion = function (rectA, rectB) {
267277
* Constructor
268278
*/
269279
cc.Rect.CCRectIntersection = function (rectA, rectB) {
270-
var intersection = new cc.Rect(
280+
var intersection = cc.rect(
271281
Math.max(cc.Rect.CCRectGetMinX(rectA), cc.Rect.CCRectGetMinX(rectB)),
272282
Math.max(cc.Rect.CCRectGetMinY(rectA), cc.Rect.CCRectGetMinY(rectB)),
273283
0, 0);
@@ -299,8 +309,16 @@ cc.SizeMake = function (width, height) {
299309
return new cc.Size(width, height);
300310
};
301311

302-
// backward compatible
303-
cc.size = cc.SizeMake;
312+
/**
313+
* @function
314+
* @param {Number} width
315+
* @param {Number} height
316+
* @return {Number, Number}
317+
* Constructor
318+
*/
319+
cc.size = function(w, h) {
320+
return new cc.Size(w,h);
321+
}
304322

305323
/**
306324
* @function
@@ -329,22 +347,22 @@ cc.PointZero = function () {
329347
};
330348

331349
/**
332-
* The "zero" size -- equivalent to cc.SizeMake(0, 0).
350+
* The "zero" size -- equivalent to cc.size(0, 0).
333351
* @function
334352
* @return {cc.Size}
335353
* Constructor
336354
*/
337355
cc.SizeZero = function () {
338-
return new cc.Size(0, 0)
356+
return cc.size(0, 0)
339357
};
340358

341359
/**
342-
* The "zero" rectangle -- equivalent to cc.RectMake(0, 0, 0, 0).
360+
* The "zero" rectangle -- equivalent to cc.rect(0, 0, 0, 0).
343361
* @function
344362
* @return {cc.Rect}
345363
* Constructor
346364
*/
347365
cc.RectZero = function () {
348-
return new cc.Rect(0, 0, 0, 0)
366+
return cc.rect(0, 0, 0, 0)
349367
};
350368

0 commit comments

Comments
 (0)