我想扩展内置Label组件,为其添加阴影:
cc.Class({
name: 'LabelEx',
extends: cc.Label,
properties: {
shadowColor: {
type: cc.Color,
default: cc.Color.BLACK
},
shadowOffset: {
type: cc.Vec2,
default: cc.Vec2.ZERO
}
},
ctor() {
this._shadowNode = null
},
onLoad() {
if (this._shadowNode !== null) return;
this._shadowNode = cc.instantiate(this.node);
this._shadowNode.color = this.shadowColor;
this._shadowNode.setPosition(cc.v2(this.node.x + this.shadowOffset.x, this.node.y + this.shadowOffset.y));
this.node.parent.addChild(this._shadowNode, this._shadowNode.zIndex - 1);
}
});
但是为sprite添加上LabelEx之后CocosCreator报错然后就卡住了。
请问如何正确扩展cocos内置组件?