Merge pull request #4033 from dingpinglv/Iss3048_cc.rect

Closed #3048: cc.rect can receiving different type parameters now
This commit is contained in:
James Chen 2013-10-30 23:52:48 -07:00
commit 77de0b580a
1 changed files with 22 additions and 4 deletions

View File

@ -230,12 +230,30 @@ cc.sizeEqualToSize = function (size1, size2)
return ((size1.width == size2.width) && (size1.height == size2.height));
};
//
// Rect
//
/**
* create a cc.rect object
* @param {Number|cc.point|cc.rect} [x] a Number value as x or a cc.point object as origin or a cc.rect clone object
* @param {Number|cc.size} [y] x1 a Number value as y or a cc.size object as size
* @param {Number} [w]
* @param {Number} [h]
* @return {Object} a cc.rect object
*/
cc.rect = function(x,y,w,h)
{
return {x:x, y:y, width:w, height:h};
var argLen = arguments.length;
if (argLen === 0)
return { x: 0, y: 0, width: 0, height: 0 };
if (argLen === 1)
return { x: x.x, y: x.y, width: x.width, height: x.height };
if (argLen === 2)
return { x: x.x, y: x.y, width: y.width, height: y.height };
if (argLen === 4)
return { x: x, y: y, width: w, height: h };
throw "unknown argument type";
};
cc._rect = function(x,y,w,h)
{