Skip to content

Commit 0f00e2a

Browse files
committed
#20: Refactor cc.Layer s to support serialization
1 parent 9311369 commit 0f00e2a

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

cocos2d/core/layers/CCLayer.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @extends cc.Node
3131
*/
3232
cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
33+
__type: "cc.Layer",
3334
_isBaked: false,
3435
_bakeSprite: null,
3536
_bakeRenderCmd: null,
@@ -65,15 +66,15 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
6566
* @function
6667
* @see cc.Layer#unbake
6768
*/
68-
bake: null,
69+
//bake: null,
6970

7071
/**
7172
* Cancel the layer to cache all of children to a bake sprite.<br/>
7273
* This is useful only in html5 engine
7374
* @function
7475
* @see cc.Layer#bake
7576
*/
76-
unbake: null,
77+
//unbake: null,
7778

7879
_bakeRendering: null,
7980

@@ -85,9 +86,9 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
8586
*/
8687
isBaked: function(){
8788
return this._isBaked;
88-
},
89+
}
8990

90-
visit: null
91+
//visit: null
9192
});
9293

9394
/**
@@ -248,6 +249,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
248249
* var yellowBox = new cc.LayerColor(cc.color(255,255,0,255), 200, 200);
249250
*/
250251
cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{
252+
__type: "cc.LayerColor",
251253
_blendFunc: null,
252254
_className: "LayerColor",
253255

@@ -317,7 +319,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{
317319
* @param {Number} [width=]
318320
* @param {Number} [height=]
319321
*/
320-
ctor: null,
322+
//ctor: null,
321323

322324
/**
323325
* Initialization of the layer, please do not call this function by yourself, you should pass the parameters to constructor to initialize a layer
@@ -388,7 +390,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{
388390
this._updateColor();
389391
},
390392

391-
draw: null
393+
//draw: null
392394
});
393395

394396
/**
@@ -585,6 +587,7 @@ delete cc._tmp.PrototypeLayerColor;
585587
* @property {Number} compresseInterpolation - Indicate whether or not the interpolation will be compressed
586588
*/
587589
cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
590+
__type: "cc.LayerGradient",
588591
_endColor: null,
589592
_startOpacity: 255,
590593
_endOpacity: 255,
@@ -835,6 +838,7 @@ delete cc._tmp.PrototypeLayerGradient;
835838
* var multiLayer = new cc.LayerMultiple(layer1, layer2, layer3);//any number of layers
836839
*/
837840
cc.LayerMultiplex = cc.Layer.extend(/** @lends cc.LayerMultiplex# */{
841+
__type: "cc.LayerMultiplex",
838842
_enabledLayer: 0,
839843
_layers: null,
840844
_className: "LayerMultiplex",

cocos2d/core/layers/CCLayerPropertyDefine.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
cc._tmp.PrototypeLayerColor = function () {
2828
var _p = cc.LayerColor.prototype;
2929
// Override properties
30-
cc.addProperty(_p, "width", _p._getWidth, _p._setWidth);
31-
cc.addProperty(_p, "height", _p._getHeight, _p._setHeight);
30+
cc.defineGetterSetter(_p, "width", _p._getWidth, _p._setWidth);
31+
cc.defineGetterSetter(_p, "height", _p._getHeight, _p._setHeight);
3232
};
3333

3434
cc._tmp.PrototypeLayerGradient = function () {
@@ -42,11 +42,16 @@ cc._tmp.PrototypeLayerGradient = function () {
4242
cc.addProperty(_p, "endColor", _p.getEndColor, _p.setEndColor);
4343
/** @expose */
4444
_p.startOpacity;
45-
cc.addProperty(_p, "startOpacity", _p.getStartOpacity, _p.setStartOpacity);
45+
cc.addProperty(_p, "startOpacity", 255, _p.getStartOpacity, _p.setStartOpacity);
4646
/** @expose */
4747
_p.endOpacity;
48-
cc.addProperty(_p, "endOpacity", _p.getEndOpacity, _p.setEndOpacity);
48+
cc.addProperty(_p, "endOpacity", 255, _p.getEndOpacity, _p.setEndOpacity);
4949
/** @expose */
5050
_p.vector;
5151
cc.addProperty(_p, "vector", _p.getVector, _p.setVector);
52+
53+
_p.__delegators = {
54+
startColor : cc.__delegators.color,
55+
endColor : cc.__delegators.color
56+
}
5257
};

0 commit comments

Comments
 (0)