cocos-awesome/assets/Scene/Home/BackHomeBtn.ts

23 lines
503 B
TypeScript
Raw Normal View History

2020-04-01 17:45:37 +00:00
const { ccclass, property } = cc._decorator;
@ccclass
export default class BackHomeBtn extends cc.Component {
static instance: BackHomeBtn = null;
2020-04-02 15:13:21 +00:00
onLoad() {
2020-04-01 17:45:37 +00:00
cc.game.addPersistRootNode(this.node);
BackHomeBtn.instance = this;
this.toggleActive(false);
2024-05-15 14:37:35 +00:00
cc.director.on('setBackBtnVisibility', this.toggleActive.bind(this));
2020-04-01 17:45:37 +00:00
}
toggleActive(flag: boolean) {
this.node.active = flag;
}
backToHome() {
this.toggleActive(false);
cc.director.loadScene('Home');
}
}