39 lines
863 B
JavaScript
39 lines
863 B
JavaScript
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
btnPrefab: {
|
|
default: null,
|
|
type: cc.Prefab
|
|
},
|
|
btns: []
|
|
},
|
|
|
|
// 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.btns.push(btn);
|
|
this.node.addChild(btn);
|
|
let y = 350 - 120 * i;
|
|
btn.setPosition(cc.v2(0, y));
|
|
}
|
|
},
|
|
|
|
start () {
|
|
},
|
|
|
|
// update (dt) {},
|
|
updateMenuShow(index) {
|
|
for(let btn of this.btns) {
|
|
let comp = btn.getComponent('topMenuBtn');
|
|
comp.selected = comp.btn_idx === index;
|
|
comp.updateStatus();
|
|
}
|
|
}
|
|
});
|