move skewX/skewY/rotation/rotationX/rotationY/scale/scaleX/scaleY to

CCNode
This commit is contained in:
Huabing.Xu
2016-12-23 11:06:25 +08:00
parent 55aaef1290
commit ac259792e1
2 changed files with 204 additions and 189 deletions
+203 -1
View File
@@ -31,6 +31,8 @@ var Flags = cc.Object.Flags;
var Destroying = Flags.Destroying;
var DontDestroy = Flags.DontDestroy;
var Activating = Flags.Activating;
var Misc = require('./utils/misc');
//var RegisteredInEditor = Flags.RegisteredInEditor;
/**
@@ -452,7 +454,156 @@ var Node = cc.Class({
this.groupIndex = cc.game.groupList.indexOf(value);
this.emit('group-changed');
}
}
},
//properties moved from base node begin
/**
* !#en Rotation of node.
* !#zh 该节点旋转角度。
* @property rotation
* @type {Number}
* @example
* node.rotation = 90;
* cc.log("Node Rotation: " + node.rotation);
*/
rotation: {
get: function () {
if (this._rotationX !== this._rotationY)
cc.logID(1602);
return this._rotationX;
},
set: function (value) {
if (this._rotationX !== value || this._rotationY !== value ) {
this._rotationX = this._rotationY = value;
this._sgNode.rotation = value;
}
}
},
/**
* !#en Rotation on x axis.
* !#zh 该节点 X 轴旋转角度。
* @property rotationX
* @type {Number}
* @example
* node.rotationX = 45;
* cc.log("Node Rotation X: " + node.rotationX);
*/
rotationX: {
get: function () {
return this._rotationX;
},
set: function (value) {
if (this._rotationX !== value) {
this._rotationX = value;
this._sgNode.rotationX = value;
}
},
},
/**
* !#en Rotation on y axis.
* !#zh 该节点 Y 轴旋转角度。
* @property rotationY
* @type {Number}
* @example
* node.rotationY = 45;
* cc.log("Node Rotation Y: " + node.rotationY);
*/
rotationY: {
get: function () {
return this._rotationY;
},
set: function (value) {
if (this._rotationY !== value) {
this._rotationY = value;
this._sgNode.rotationY = value;
}
},
},
/**
* !#en Scale on x axis.
* !#zh 节点 X 轴缩放。
* @property scaleX
* @type {Number}
* @example
* node.scaleX = 0.5;
* cc.log("Node Scale X: " + node.scaleX);
*/
scaleX: {
get: function () {
return this._scaleX;
},
set: function (value) {
if (this._scaleX !== value) {
this._scaleX = value;
this._sgNode.scaleX = value;
}
},
},
/**
* !#en Scale on y axis.
* !#zh 节点 Y 轴缩放。
* @property scaleY
* @type {Number}
* @example
* node.scaleY = 0.5;
* cc.log("Node Scale Y: " + node.scaleY);
*/
scaleY: {
get: function () {
return this._scaleY;
},
set: function (value) {
if (this._scaleY !== value) {
this._scaleY = value;
this._sgNode.scaleY = value;
}
},
},
/**
* !#en Skew x
* !#zh 该节点 Y 轴倾斜角度。
* @property skewX
* @type {Number}
* @example
* node.skewX = 0;
* cc.log("Node SkewX: " + node.skewX);
*/
skewX: {
get: function () {
return this._skewX;
},
set: function (value) {
this._skewX = value;
this._sgNode.skewX = value;
}
},
/**
* !#en Skew y
* !#zh 该节点 X 轴倾斜角度。
* @property skewY
* @type {Number}
* @example
* node.skewY = 0;
* cc.log("Node SkewY: " + node.skewY);
*/
skewY: {
get: function () {
return this._skewY;
},
set: function (value) {
this._skewY = value;
this._sgNode.skewY = value;
}
},
//properties moved from base node end
},
ctor: function (name) {
@@ -1475,6 +1626,51 @@ var Node = cc.Class({
}
},
//functions moved from base node begin
/**
* !#en
* Returns the scale factor of the node.
* Assertion will fail when _scaleX != _scaleY.
* !#zh 获取节点的缩放。当 X 轴和 Y 轴有相同的缩放数值时。
* @method getScale
* @return {Number} The scale factor
* @example
* cc.log("Node Scale: " + node.getScale());
*/
getScale: function () {
if (this._scaleX !== this._scaleY)
cc.logID(1603);
return this._scaleX;
},
/**
* !#en Sets the scale factor of the node. 1.0 is the default scale factor. This function can modify the X and Y scale at the same time.
* !#zh 设置节点的缩放比例,默认值为 1.0。这个函数可以在同一时间修改 X 和 Y 缩放。
* @method setScale
* @param {Number|Vec2} scaleX - scaleX or scale
* @param {Number} [scaleY=scale]
* @example
* node.setScale(cc.v2(1, 1));
* node.setScale(1, 1);
*/
setScale: function (scaleX, scaleY) {
if (typeof scaleX === 'object') {
scaleY = scaleX.y;
scaleX = scaleX.x
}
else {
scaleY = (scaleY || scaleY === 0) ? scaleY : scaleX;
}
if (this._scaleX !== scaleX || this._scaleY !== scaleY) {
this._scaleX = scaleX;
this._scaleY = scaleY;
this._sgNode.setScale(scaleX, scaleY);
}
},
//functions moved from base node end
});
// In JSB, when inner sg node being replaced, the system event listeners will be cleared.
@@ -1673,6 +1869,12 @@ if (CC_JSB) {
* node.setCascadeColorEnabled(true);
*/
var SameNameGetSets = ['skewX', 'skewY', 'rotation', 'rotationX', 'rotationY', 'scale', 'scaleX', 'scaleY', ];
var DiffNameGetSets = {
};
Misc.propertyDefine(Node, SameNameGetSets, DiffNameGetSets);
Node.EventType = EventType;
+1 -188
View File
@@ -147,44 +147,6 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
}
},
/**
* !#en Skew x
* !#zh 该节点 Y 轴倾斜角度。
* @property skewX
* @type {Number}
* @example
* node.skewX = 0;
* cc.log("Node SkewX: " + node.skewX);
*/
skewX: {
get: function () {
return this._skewX;
},
set: function (value) {
this._skewX = value;
this._sgNode.skewX = value;
}
},
/**
* !#en Skew y
* !#zh 该节点 X 轴倾斜角度。
* @property skewY
* @type {Number}
* @example
* node.skewY = 0;
* cc.log("Node SkewY: " + node.skewY);
*/
skewY: {
get: function () {
return this._skewY;
},
set: function (value) {
this._skewY = value;
this._sgNode.skewY = value;
}
},
/**
* !#en Z order in depth which stands for the drawing order.
* !#zh 该节点渲染排序的 Z 轴深度。
@@ -210,113 +172,6 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
}
},
/**
* !#en Rotation of node.
* !#zh 该节点旋转角度。
* @property rotation
* @type {Number}
* @example
* node.rotation = 90;
* cc.log("Node Rotation: " + node.rotation);
*/
rotation: {
get: function () {
if (this._rotationX !== this._rotationY)
cc.logID(1602);
return this._rotationX;
},
set: function (value) {
if (this._rotationX !== value || this._rotationY !== value ) {
this._rotationX = this._rotationY = value;
this._sgNode.rotation = value;
}
}
},
/**
* !#en Rotation on x axis.
* !#zh 该节点 X 轴旋转角度。
* @property rotationX
* @type {Number}
* @example
* node.rotationX = 45;
* cc.log("Node Rotation X: " + node.rotationX);
*/
rotationX: {
get: function () {
return this._rotationX;
},
set: function (value) {
if (this._rotationX !== value) {
this._rotationX = value;
this._sgNode.rotationX = value;
}
},
},
/**
* !#en Rotation on y axis.
* !#zh 该节点 Y 轴旋转角度。
* @property rotationY
* @type {Number}
* @example
* node.rotationY = 45;
* cc.log("Node Rotation Y: " + node.rotationY);
*/
rotationY: {
get: function () {
return this._rotationY;
},
set: function (value) {
if (this._rotationY !== value) {
this._rotationY = value;
this._sgNode.rotationY = value;
}
},
},
/**
* !#en Scale on x axis.
* !#zh 节点 X 轴缩放。
* @property scaleX
* @type {Number}
* @example
* node.scaleX = 0.5;
* cc.log("Node Scale X: " + node.scaleX);
*/
scaleX: {
get: function () {
return this._scaleX;
},
set: function (value) {
if (this._scaleX !== value) {
this._scaleX = value;
this._sgNode.scaleX = value;
}
},
},
/**
* !#en Scale on y axis.
* !#zh 节点 Y 轴缩放。
* @property scaleY
* @type {Number}
* @example
* node.scaleY = 0.5;
* cc.log("Node Scale Y: " + node.scaleY);
*/
scaleY: {
get: function () {
return this._scaleY;
},
set: function (value) {
if (this._scaleY !== value) {
this._scaleY = value;
this._sgNode.scaleY = value;
}
},
},
/**
* !#en x axis position of node.
* !#zh 节点 X 轴坐标。
@@ -886,47 +741,6 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
return this._globalZOrder;
},
/**
* !#en
* Returns the scale factor of the node.
* Assertion will fail when _scaleX != _scaleY.
* !#zh 获取节点的缩放。当 X 轴和 Y 轴有相同的缩放数值时。
* @method getScale
* @return {Number} The scale factor
* @example
* cc.log("Node Scale: " + node.getScale());
*/
getScale: function () {
if (this._scaleX !== this._scaleY)
cc.logID(1603);
return this._scaleX;
},
/**
* !#en Sets the scale factor of the node. 1.0 is the default scale factor. This function can modify the X and Y scale at the same time.
* !#zh 设置节点的缩放比例,默认值为 1.0。这个函数可以在同一时间修改 X 和 Y 缩放。
* @method setScale
* @param {Number|Vec2} scaleX - scaleX or scale
* @param {Number} [scaleY=scale]
* @example
* node.setScale(cc.v2(1, 1));
* node.setScale(1, 1);
*/
setScale: function (scaleX, scaleY) {
if (typeof scaleX === 'object') {
scaleY = scaleX.y;
scaleX = scaleX.x
}
else {
scaleY = (scaleY || scaleY === 0) ? scaleY : scaleX;
}
if (this._scaleX !== scaleX || this._scaleY !== scaleY) {
this._scaleX = scaleX;
this._scaleY = scaleY;
this._sgNode.setScale(scaleX, scaleY);
}
},
/**
* !#en Returns a copy of the position (x,y) of the node in cocos2d coordinates. (0,0) is the left-bottom corner.
* !#zh 获取在父节点坐标系中节点的位置( x , y )。
@@ -2070,8 +1884,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
// Define public getter and setter methods to ensure api compatibility.
var SameNameGetSets = ['name', 'skewX', 'skewY', 'position', 'rotation', 'rotationX', 'rotationY',
'scale', 'scaleX', 'scaleY', 'children', 'childrenCount', 'parent',
var SameNameGetSets = ['name', 'position', 'children', 'childrenCount', 'parent',
/*'shaderProgram',*/ 'opacity', 'color', 'tag'];
var DiffNameGetSets = {
x: ['getPositionX', 'setPositionX'],