-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathApp.ts
41 lines (34 loc) · 1.22 KB
/
App.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export default class App {
constructor() {
this.initConfig();
}
currentTheme: string = "yellow";
initConfig() {
Laya.URL.basePath = "./res/fgui/"
Laya.stage.addChild(fgui.GRoot.inst.displayObject);
let theme: string = Laya.Utils.getQueryString("theme");
if (theme) {
console.log("当前主题:", theme);
this.currentTheme = theme;
}
this.loadRes();
}
loadRes() {
Laya.loader.load([
{ url: "Pet.fui", type: Laya.Loader.BUFFER },
{ url: `${this.currentTheme}/Asset.fui`, type: Laya.Loader.BUFFER },
{ url: `${this.currentTheme}/Asset_atlas0.png`, type: Laya.Loader.IMAGE },
], Laya.Handler.create(this, this.init));
}
init() {
fgui.UIPackage.addPackage(`${this.currentTheme}/Asset`);
fgui.UIPackage.addPackage("Pet");
let view = fgui.UIPackage.createObject("Pet", "Main").asCom;
fgui.GRoot.inst.addChild(view);
view.getChild("btn_change").onClick(this, this.change);
}
change() {
this.currentTheme = this.currentTheme == "yellow" ? "blue" : "yellow";
location.href = `index.html?theme=${this.currentTheme}`;
}
}