Hello everyone i want to inherit a class to layer. But when i am adding layer to scene then error is thrown- "CCDebugger.js :322 Uncaught Error: child already added. It can’t be added again ".
Is there any other way to inherit class?
My code is -
var CommonActions = cc.Class.extend({
cardName: null,
flipCards: function () {
},
resetPosition: function () {
}
});
var HelloWorldLayer = cc.Layer.extend({
ctor: function (noOfPlayer) {
//////////////////////////////
// 1. super init first
this._super();
var size = cc.winSize;
var bg = new cc.Sprite(res.HelloWorld_png);
bg.setPosition(960 / 2, 640 / 2);
this.addChild(bg);
return true;
},
flipCards: function () {
// overridden function
},
resetPosition: function () {
// overridden function
}
});
HelloWorldLayer.prototype = new CommonActions();
var HelloWorldScene = cc.Scene.extend({
onEnter: function () {
this._super();
var layer1 = new HelloWorldLayer();
this.addChild(layer1);
}
});