cc.Class({ extends: cc.Component, properties: { btnPrefab: { default: null, type: cc.Prefab }, }, // LIFE-CYCLE CALLBACKS: onLoad () { for (let i = 0 ; i < 5; i++) { var btn = cc.instantiate(this.btnPrefab); btn.getComponent('topMenuBtn').btn_idx = i; btn.getComponent('topMenuBtn').selected = i === 0; this.node.addChild(btn); let y = 400 - 120 * i; btn.setPosition(cc.v2(0, y)); } }, start () { }, // update (dt) {}, });