我尽量还原截图里的组件代码,我这里没有问题,在 index.js 和 modules.json 添加相应的内容就添加好了组件
官方的提交记录也是只在这两个地方加了内容
提交链接
组件
/**
* Who
* @class WhoComponet
* @extends Component
*/
var WhoComponet = cc.Class({
name: 'WhoComponet',
extends: require('./CCComponent'),
editor: CC_EDITOR && {
// help: 'i18n:COMPONENT.help_url.safe_area',
menu: 'i18n:MAIN_MENU.component.ui/WhoComponent',
// inspector: 'packages://inspector/inspectors/comps/safe-area.js',
executeInEditMode: true,
// requireComponent: Widget,
},
properties: {
/**
* !#en Content string of RichText.
* !#zh 富文本显示的文本内容。
* @property {String} string
*/
string: {
default: '<color=#00ff00>Rich</c><color=#0fffff>Text</color>',
multiline: true,
tooltip: CC_DEV && 'i18n:COMPONENT.richtext.string'
},
},
ctor() {
this._textArray = null;
this._labelSegments = [];
this._labelSegmentsCache = [];
this._linesWidth = [];
},
onLoad() {
cc.log("success!");
},
onDestroy() {
cc.log("byebye!");
}
});
module.exports = WhoComponet;
index.js
require('./WhoComponet'),
modules.json
{
"name": "WhoComponet",
"since": "2.4.0",
"entries": [
"./cocos2d/core/components/WhoComponet.js"
]
}
效果
我用的是 2.4.3-rc4 测试的,供参考